[feat] show shield icon when SRTP is enabled

This commit is contained in:
dijunkun
2025-09-30 17:26:42 +08:00
parent 6565816c0e
commit 15bf8ef8c0
4 changed files with 61 additions and 62 deletions

View File

@@ -259,7 +259,7 @@ int Render::NetTrafficStats(std::shared_ptr<SubStreamWindowProperties>& props) {
if (ImGui::BeginTable("NetTrafficStats", 4, ImGuiTableFlags_BordersH, if (ImGui::BeginTable("NetTrafficStats", 4, ImGuiTableFlags_BordersH,
ImVec2(props->control_window_max_width_ - 10.0f, ImVec2(props->control_window_max_width_ - 10.0f,
props->control_window_max_height_ - 40.0f))) { props->control_window_max_height_ - 60.0f))) {
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed); ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthStretch); ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthStretch); ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthStretch);
@@ -275,7 +275,6 @@ int Render::NetTrafficStats(std::shared_ptr<SubStreamWindowProperties>& props) {
ImGui::Text("%s", ImGui::Text("%s",
localization::loss_rate[localization_language_index_].c_str()); localization::loss_rate[localization_language_index_].c_str());
ImGui::TableNextRow();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::Text("%s", ImGui::Text("%s",
localization::video[localization_language_index_].c_str()); localization::video[localization_language_index_].c_str());
@@ -286,7 +285,6 @@ int Render::NetTrafficStats(std::shared_ptr<SubStreamWindowProperties>& props) {
ImGui::TableNextColumn(); ImGui::TableNextColumn();
LossRateDisplay(props->net_traffic_stats_.video_inbound_stats.loss_rate); LossRateDisplay(props->net_traffic_stats_.video_inbound_stats.loss_rate);
ImGui::TableNextRow();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::Text("%s", ImGui::Text("%s",
localization::audio[localization_language_index_].c_str()); localization::audio[localization_language_index_].c_str());
@@ -297,7 +295,6 @@ int Render::NetTrafficStats(std::shared_ptr<SubStreamWindowProperties>& props) {
ImGui::TableNextColumn(); ImGui::TableNextColumn();
LossRateDisplay(props->net_traffic_stats_.audio_inbound_stats.loss_rate); LossRateDisplay(props->net_traffic_stats_.audio_inbound_stats.loss_rate);
ImGui::TableNextRow();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::Text("%s", localization::data[localization_language_index_].c_str()); ImGui::Text("%s", localization::data[localization_language_index_].c_str());
ImGui::TableNextColumn(); ImGui::TableNextColumn();
@@ -307,7 +304,6 @@ int Render::NetTrafficStats(std::shared_ptr<SubStreamWindowProperties>& props) {
ImGui::TableNextColumn(); ImGui::TableNextColumn();
LossRateDisplay(props->net_traffic_stats_.data_inbound_stats.loss_rate); LossRateDisplay(props->net_traffic_stats_.data_inbound_stats.loss_rate);
ImGui::TableNextRow();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::Text("%s", ImGui::Text("%s",
localization::total[localization_language_index_].c_str()); localization::total[localization_language_index_].c_str());

View File

@@ -34,7 +34,7 @@ class Render {
public: public:
struct SubStreamWindowProperties { struct SubStreamWindowProperties {
Params params_; Params params_;
PeerPtr *peer_ = nullptr; PeerPtr* peer_ = nullptr;
std::string audio_label_ = "control_audio"; std::string audio_label_ = "control_audio";
std::string data_label_ = "control_data"; std::string data_label_ = "control_data";
std::string local_id_ = ""; std::string local_id_ = "";
@@ -74,7 +74,7 @@ class Render {
float mouse_diff_control_bar_pos_y_ = 0; float mouse_diff_control_bar_pos_y_ = 0;
double control_bar_button_pressed_time_ = 0; double control_bar_button_pressed_time_ = 0;
double net_traffic_stats_button_pressed_time_ = 0; double net_traffic_stats_button_pressed_time_ = 0;
unsigned char *dst_buffer_ = nullptr; unsigned char* dst_buffer_ = nullptr;
size_t dst_buffer_capacity_ = 0; size_t dst_buffer_capacity_ = 0;
float mouse_pos_x_ = 0; float mouse_pos_x_ = 0;
float mouse_pos_y_ = 0; float mouse_pos_y_ = 0;
@@ -102,8 +102,8 @@ class Render {
std::string audio_capture_button_label_ = "Audio Capture"; std::string audio_capture_button_label_ = "Audio Capture";
std::string remote_host_name_ = ""; std::string remote_host_name_ = "";
std::vector<DisplayInfo> display_info_list_; std::vector<DisplayInfo> display_info_list_;
SDL_Texture *stream_texture_ = nullptr; SDL_Texture* stream_texture_ = nullptr;
uint8_t *argb_buffer_ = nullptr; uint8_t* argb_buffer_ = nullptr;
int argb_buffer_size_ = 0; int argb_buffer_size_ = 0;
SDL_Rect stream_render_rect_; SDL_Rect stream_render_rect_;
SDL_Rect stream_render_rect_last_; SDL_Rect stream_render_rect_last_;
@@ -138,7 +138,7 @@ class Render {
void CleanSubStreamWindowProperties( void CleanSubStreamWindowProperties(
std::shared_ptr<SubStreamWindowProperties> props); std::shared_ptr<SubStreamWindowProperties> props);
void UpdateRenderRect(); void UpdateRenderRect();
void ProcessSdlEvent(const SDL_Event &event); void ProcessSdlEvent(const SDL_Event& event);
private: private:
int CreateStreamRenderWindow(); int CreateStreamRenderWindow();
@@ -149,16 +149,16 @@ class Render {
int RemoteWindow(); int RemoteWindow();
int RecentConnectionsWindow(); int RecentConnectionsWindow();
int SettingWindow(); int SettingWindow();
int ControlWindow(std::shared_ptr<SubStreamWindowProperties> &props); int ControlWindow(std::shared_ptr<SubStreamWindowProperties>& props);
int ControlBar(std::shared_ptr<SubStreamWindowProperties> &props); int ControlBar(std::shared_ptr<SubStreamWindowProperties>& props);
int AboutWindow(); int AboutWindow();
int StatusBar(); int StatusBar();
bool ConnectionStatusWindow( bool ConnectionStatusWindow(
std::shared_ptr<SubStreamWindowProperties> &props); std::shared_ptr<SubStreamWindowProperties>& props);
int ShowRecentConnections(); int ShowRecentConnections();
private: private:
int ConnectTo(const std::string &remote_id, const char *password, int ConnectTo(const std::string& remote_id, const char* password,
bool remember_password); bool remember_password);
int CreateMainWindow(); int CreateMainWindow();
int DestroyMainWindow(); int DestroyMainWindow();
@@ -172,51 +172,51 @@ class Render {
int DrawMainWindow(); int DrawMainWindow();
int DrawStreamWindow(); int DrawStreamWindow();
int ConfirmDeleteConnection(); int ConfirmDeleteConnection();
int NetTrafficStats(std::shared_ptr<SubStreamWindowProperties> &props); int NetTrafficStats(std::shared_ptr<SubStreamWindowProperties>& props);
void DrawConnectionStatusText( void DrawConnectionStatusText(
std::shared_ptr<SubStreamWindowProperties> &props); std::shared_ptr<SubStreamWindowProperties>& props);
public: public:
static void OnReceiveVideoBufferCb(const XVideoFrame *video_frame, static void OnReceiveVideoBufferCb(const XVideoFrame* video_frame,
const char *user_id, size_t user_id_size, const char* user_id, size_t user_id_size,
void *user_data); void* user_data);
static void OnReceiveAudioBufferCb(const char *data, size_t size, static void OnReceiveAudioBufferCb(const char* data, size_t size,
const char *user_id, size_t user_id_size, const char* user_id, size_t user_id_size,
void *user_data); void* user_data);
static void OnReceiveDataBufferCb(const char *data, size_t size, static void OnReceiveDataBufferCb(const char* data, size_t size,
const char *user_id, size_t user_id_size, const char* user_id, size_t user_id_size,
void *user_data); void* user_data);
static void OnSignalStatusCb(SignalStatus status, const char *user_id, static void OnSignalStatusCb(SignalStatus status, const char* user_id,
size_t user_id_size, void *user_data); size_t user_id_size, void* user_data);
static void OnConnectionStatusCb(ConnectionStatus status, const char *user_id, static void OnConnectionStatusCb(ConnectionStatus status, const char* user_id,
size_t user_id_size, void *user_data); size_t user_id_size, void* user_data);
static void NetStatusReport(const char *client_id, size_t client_id_size, static void NetStatusReport(const char* client_id, size_t client_id_size,
TraversalMode mode, TraversalMode mode,
const XNetTrafficStats *net_traffic_stats, const XNetTrafficStats* net_traffic_stats,
const char *user_id, const size_t user_id_size, const char* user_id, const size_t user_id_size,
void *user_data); void* user_data);
static SDL_HitTestResult HitTestCallback(SDL_Window *window, static SDL_HitTestResult HitTestCallback(SDL_Window* window,
const SDL_Point *area, void *data); const SDL_Point* area, void* data);
static std::vector<char> SerializeRemoteAction(const RemoteAction &action); static std::vector<char> SerializeRemoteAction(const RemoteAction& action);
static bool DeserializeRemoteAction(const char *data, size_t size, static bool DeserializeRemoteAction(const char* data, size_t size,
RemoteAction &out); RemoteAction& out);
static void FreeRemoteAction(RemoteAction &action); static void FreeRemoteAction(RemoteAction& action);
private: private:
int SendKeyCommand(int key_code, bool is_down); int SendKeyCommand(int key_code, bool is_down);
int ProcessMouseEvent(const SDL_Event &event); int ProcessMouseEvent(const SDL_Event& event);
static void SdlCaptureAudioIn(void *userdata, Uint8 *stream, int len); static void SdlCaptureAudioIn(void* userdata, Uint8* stream, int len);
static void SdlCaptureAudioOut(void *userdata, Uint8 *stream, int len); static void SdlCaptureAudioOut(void* userdata, Uint8* stream, int len);
private: private:
int SaveSettingsIntoCacheFile(); int SaveSettingsIntoCacheFile();
@@ -287,9 +287,9 @@ class Render {
uint32_t recent_connection_image_save_time_ = 0; uint32_t recent_connection_image_save_time_ = 0;
// main window render // main window render
SDL_Window *main_window_ = nullptr; SDL_Window* main_window_ = nullptr;
SDL_Renderer *main_renderer_ = nullptr; SDL_Renderer* main_renderer_ = nullptr;
ImGuiContext *main_ctx_ = nullptr; ImGuiContext* main_ctx_ = nullptr;
bool exit_ = false; bool exit_ = false;
const int sdl_refresh_ms_ = 16; // ~60 FPS const int sdl_refresh_ms_ = 16; // ~60 FPS
@@ -349,13 +349,13 @@ class Render {
std::string focused_remote_id_ = ""; std::string focused_remote_id_ = "";
bool need_to_send_host_info_ = false; bool need_to_send_host_info_ = false;
SDL_Event last_mouse_event; SDL_Event last_mouse_event;
SDL_AudioStream *output_stream_; SDL_AudioStream* output_stream_;
uint32_t STREAM_REFRESH_EVENT = 0; uint32_t STREAM_REFRESH_EVENT = 0;
// stream window render // stream window render
SDL_Window *stream_window_ = nullptr; SDL_Window* stream_window_ = nullptr;
SDL_Renderer *stream_renderer_ = nullptr; SDL_Renderer* stream_renderer_ = nullptr;
ImGuiContext *stream_ctx_ = nullptr; ImGuiContext* stream_ctx_ = nullptr;
// stream window properties // stream window properties
bool need_to_create_stream_window_ = false; bool need_to_create_stream_window_ = false;
@@ -400,8 +400,8 @@ class Render {
SignalStatus signal_status_ = SignalStatus::SignalClosed; SignalStatus signal_status_ = SignalStatus::SignalClosed;
std::string signal_status_str_ = ""; std::string signal_status_str_ = "";
bool signal_connected_ = false; bool signal_connected_ = false;
PeerPtr *peer_ = nullptr; PeerPtr* peer_ = nullptr;
PeerPtr *peer_reserved_ = nullptr; PeerPtr* peer_reserved_ = nullptr;
std::string video_primary_label_ = "primary_display"; std::string video_primary_label_ = "primary_display";
std::string video_secondary_label_ = "secondary_display"; std::string video_secondary_label_ = "secondary_display";
std::string audio_label_ = "audio"; std::string audio_label_ = "audio";
@@ -409,13 +409,13 @@ class Render {
Params params_; Params params_;
SDL_AudioDeviceID input_dev_; SDL_AudioDeviceID input_dev_;
SDL_AudioDeviceID output_dev_; SDL_AudioDeviceID output_dev_;
ScreenCapturerFactory *screen_capturer_factory_ = nullptr; ScreenCapturerFactory* screen_capturer_factory_ = nullptr;
ScreenCapturer *screen_capturer_ = nullptr; ScreenCapturer* screen_capturer_ = nullptr;
SpeakerCapturerFactory *speaker_capturer_factory_ = nullptr; SpeakerCapturerFactory* speaker_capturer_factory_ = nullptr;
SpeakerCapturer *speaker_capturer_ = nullptr; SpeakerCapturer* speaker_capturer_ = nullptr;
DeviceControllerFactory *device_controller_factory_ = nullptr; DeviceControllerFactory* device_controller_factory_ = nullptr;
MouseController *mouse_controller_ = nullptr; MouseController* mouse_controller_ = nullptr;
KeyboardCapturer *keyboard_capturer_ = nullptr; KeyboardCapturer* keyboard_capturer_ = nullptr;
std::vector<DisplayInfo> display_info_list_; std::vector<DisplayInfo> display_info_list_;
uint64_t last_frame_time_; uint64_t last_frame_time_;
char client_id_[10] = ""; char client_id_[10] = "";
@@ -440,7 +440,7 @@ class Render {
/* ------ sub stream window property start ------ */ /* ------ sub stream window property start ------ */
std::unordered_map<std::string, std::shared_ptr<SubStreamWindowProperties>> std::unordered_map<std::string, std::shared_ptr<SubStreamWindowProperties>>
client_properties_; client_properties_;
void CloseTab(decltype(client_properties_)::iterator &it); void CloseTab(decltype(client_properties_)::iterator& it);
/* ------ stream window property end ------ */ /* ------ stream window property end ------ */
}; };

View File

@@ -86,8 +86,11 @@ int Render::StreamWindow() {
} }
ImGui::SetWindowFontScale(0.6f); ImGui::SetWindowFontScale(0.6f);
if (ImGui::BeginTabItem(props->remote_id_.c_str(), std::string tab_label =
&props->tab_opened_)) { enable_srtp_
? std::string(ICON_FA_SHIELD_HALVED) + " " + props->remote_id_
: props->remote_id_;
if (ImGui::BeginTabItem(tab_label.c_str(), &props->tab_opened_)) {
props->tab_selected_ = true; props->tab_selected_ = true;
ImGui::SetWindowFontScale(1.0f); ImGui::SetWindowFontScale(1.0f);