[feat] enable speaker capturer by default

This commit is contained in:
dijunkun
2025-11-10 15:02:21 +08:00
parent 0d591f769d
commit 78eb069cc8
5 changed files with 29 additions and 17 deletions

View File

@@ -566,6 +566,14 @@ void Render::UpdateInteractions() {
screen_capturer_is_started_ = false; screen_capturer_is_started_ = false;
} }
if (start_speaker_capturer_ && !speaker_capturer_is_started_) {
StartSpeakerCapturer();
speaker_capturer_is_started_ = true;
} else if (!start_speaker_capturer_ && speaker_capturer_is_started_) {
StopSpeakerCapturer();
speaker_capturer_is_started_ = false;
}
if (start_mouse_controller_ && !mouse_controller_is_started_) { if (start_mouse_controller_ && !mouse_controller_is_started_) {
StartMouseController(); StartMouseController();
mouse_controller_is_started_ = true; mouse_controller_is_started_ = true;
@@ -1055,9 +1063,9 @@ void Render::MainLoop() {
remote_action.i.host_name[host_name.size()] = '\0'; remote_action.i.host_name[host_name.size()] = '\0';
remote_action.i.host_name_size = host_name.size(); remote_action.i.host_name_size = host_name.size();
std::vector<char> serialized = SerializeRemoteAction(remote_action); std::string msg = remote_action.to_json();
int ret = SendDataFrame(peer_, serialized.data(), serialized.size(), int ret =
data_label_.c_str()); SendDataFrame(peer_, msg.data(), msg.size(), data_label_.c_str());
FreeRemoteAction(remote_action); FreeRemoteAction(remote_action);
if (0 == ret) { if (0 == ret) {
need_to_send_host_info_ = false; need_to_send_host_info_ = false;

View File

@@ -51,7 +51,7 @@ class Render {
bool net_traffic_stats_button_pressed_ = false; bool net_traffic_stats_button_pressed_ = false;
bool mouse_control_button_pressed_ = false; bool mouse_control_button_pressed_ = false;
bool mouse_controller_is_started_ = false; bool mouse_controller_is_started_ = false;
bool audio_capture_button_pressed_ = false; bool audio_capture_button_pressed_ = true;
bool control_mouse_ = false; bool control_mouse_ = false;
bool streaming_ = false; bool streaming_ = false;
bool is_control_bar_in_left_ = true; bool is_control_bar_in_left_ = true;
@@ -311,6 +311,8 @@ class Render {
bool mouse_controller_is_started_ = false; bool mouse_controller_is_started_ = false;
bool start_screen_capturer_ = false; bool start_screen_capturer_ = false;
bool screen_capturer_is_started_ = false; bool screen_capturer_is_started_ = false;
bool start_speaker_capturer_ = false;
bool speaker_capturer_is_started_ = false;
bool start_keyboard_capturer_ = false; bool start_keyboard_capturer_ = false;
bool keyboard_capturer_is_started_ = false; bool keyboard_capturer_is_started_ = false;
bool foucs_on_main_window_ = false; bool foucs_on_main_window_ = false;

View File

@@ -28,8 +28,7 @@ int Render::SendKeyCommand(int key_code, bool is_down) {
client_properties_.end()) { client_properties_.end()) {
auto props = client_properties_[controlled_remote_id_]; auto props = client_properties_[controlled_remote_id_];
if (props->connection_status_ == ConnectionStatus::Connected) { if (props->connection_status_ == ConnectionStatus::Connected) {
json j = remote_action.to_json(); std::string msg = remote_action.to_json();
std::string msg = j.dump();
SendDataFrame(props->peer_, msg.c_str(), msg.size(), SendDataFrame(props->peer_, msg.c_str(), msg.size(),
props->data_label_.c_str()); props->data_label_.c_str());
} }
@@ -97,8 +96,7 @@ int Render::ProcessMouseEvent(const SDL_Event& event) {
remote_action.m.flag = MouseFlag::move; remote_action.m.flag = MouseFlag::move;
} }
json j = remote_action.to_json(); std::string msg = remote_action.to_json();
std::string msg = j.dump();
SendDataFrame(props->peer_, msg.c_str(), msg.size(), SendDataFrame(props->peer_, msg.c_str(), msg.size(),
props->data_label_.c_str()); props->data_label_.c_str());
} else if (SDL_EVENT_MOUSE_WHEEL == event.type && } else if (SDL_EVENT_MOUSE_WHEEL == event.type &&
@@ -132,8 +130,7 @@ int Render::ProcessMouseEvent(const SDL_Event& event) {
(float)(event.button.y - props->stream_render_rect_.y) / (float)(event.button.y - props->stream_render_rect_.y) /
render_height; render_height;
json j = remote_action.to_json(); std::string msg = remote_action.to_json();
std::string msg = j.dump();
SendDataFrame(props->peer_, msg.c_str(), msg.size(), SendDataFrame(props->peer_, msg.c_str(), msg.size(),
props->data_label_.c_str()); props->data_label_.c_str());
} }
@@ -321,9 +318,9 @@ void Render::OnReceiveDataBufferCb(const char* data, size_t size,
render->mouse_controller_->SendMouseCommand(remote_action, render->mouse_controller_->SendMouseCommand(remote_action,
render->selected_display_); render->selected_display_);
} else if (remote_action.type == ControlType::audio_capture) { } else if (remote_action.type == ControlType::audio_capture) {
if (remote_action.a) if (remote_action.a && !render->start_speaker_capturer_)
render->StartSpeakerCapturer(); render->StartSpeakerCapturer();
else else if (!remote_action.a && render->start_speaker_capturer_)
render->StopSpeakerCapturer(); render->StopSpeakerCapturer();
} else if (remote_action.type == ControlType::keyboard && } else if (remote_action.type == ControlType::keyboard &&
render->keyboard_capturer_) { render->keyboard_capturer_) {
@@ -422,6 +419,7 @@ void Render::OnConnectionStatusCb(ConnectionStatus status, const char* user_id,
case ConnectionStatus::Closed: case ConnectionStatus::Closed:
render->password_validating_time_ = 0; render->password_validating_time_ = 0;
render->start_screen_capturer_ = false; render->start_screen_capturer_ = false;
render->start_speaker_capturer_ = false;
render->start_mouse_controller_ = false; render->start_mouse_controller_ = false;
render->start_keyboard_capturer_ = false; render->start_keyboard_capturer_ = false;
render->control_mouse_ = false; render->control_mouse_ = false;
@@ -462,10 +460,12 @@ void Render::OnConnectionStatusCb(ConnectionStatus status, const char* user_id,
case ConnectionStatus::Connected: case ConnectionStatus::Connected:
render->need_to_send_host_info_ = true; render->need_to_send_host_info_ = true;
render->start_screen_capturer_ = true; render->start_screen_capturer_ = true;
render->start_speaker_capturer_ = true;
render->start_mouse_controller_ = true; render->start_mouse_controller_ = true;
break; break;
case ConnectionStatus::Closed: case ConnectionStatus::Closed:
render->start_screen_capturer_ = false; render->start_screen_capturer_ = false;
render->start_speaker_capturer_ = false;
render->start_mouse_controller_ = false; render->start_mouse_controller_ = false;
render->start_keyboard_capturer_ = false; render->start_keyboard_capturer_ = false;
render->need_to_send_host_info_ = false; render->need_to_send_host_info_ = false;

View File

@@ -68,8 +68,9 @@ int Render::ControlBar(std::shared_ptr<SubStreamWindowProperties>& props) {
remote_action.type = ControlType::display_id; remote_action.type = ControlType::display_id;
remote_action.d = i; remote_action.d = i;
if (props->connection_status_ == ConnectionStatus::Connected) { if (props->connection_status_ == ConnectionStatus::Connected) {
SendDataFrame(props->peer_, (const char*)&remote_action, std::string msg = remote_action.to_json();
sizeof(remote_action), props->data_label_.c_str()); SendDataFrame(props->peer_, msg.c_str(), msg.size(),
props->data_label_.c_str());
} }
} }
props->display_selectable_hovered_ = ImGui::IsWindowHovered(); props->display_selectable_hovered_ = ImGui::IsWindowHovered();
@@ -142,8 +143,9 @@ int Render::ControlBar(std::shared_ptr<SubStreamWindowProperties>& props) {
RemoteAction remote_action; RemoteAction remote_action;
remote_action.type = ControlType::audio_capture; remote_action.type = ControlType::audio_capture;
remote_action.a = props->audio_capture_button_pressed_; remote_action.a = props->audio_capture_button_pressed_;
SendDataFrame(props->peer_, (const char*)&remote_action, std::string msg = remote_action.to_json();
sizeof(remote_action), props->data_label_.c_str()); SendDataFrame(props->peer_, msg.c_str(), msg.size(),
props->data_label_.c_str());
} }
} }
if (!props->audio_capture_button_pressed_) { if (!props->audio_capture_button_pressed_) {