mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-27 04:35:34 +08:00
[fix] fix all unused variables and type conversions
This commit is contained in:
@@ -3,9 +3,9 @@
|
||||
#include "rd_log.h"
|
||||
#include "render.h"
|
||||
|
||||
int CountDigits(int number) {
|
||||
int CountDigits(uint64_t number) {
|
||||
if (number == 0) return 1;
|
||||
return std::floor(std::log10(std::abs(number))) + 1;
|
||||
return (int)std::floor(std::log10(std::abs((int)number))) + 1;
|
||||
}
|
||||
|
||||
int BitrateDisplay(uint64_t bitrate) {
|
||||
@@ -192,7 +192,7 @@ int Render::ControlBar() {
|
||||
}
|
||||
|
||||
if (net_traffic_stats_button_pressed_ && control_bar_expand_) {
|
||||
NetTrafficStats(mouse_button_pos);
|
||||
NetTrafficStats();
|
||||
}
|
||||
|
||||
ImGui::PopStyleVar();
|
||||
@@ -200,7 +200,7 @@ int Render::ControlBar() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Render::NetTrafficStats(ImVec2 mouse_button_pos) {
|
||||
int Render::NetTrafficStats() {
|
||||
ImGui::SetCursorPos(ImVec2(
|
||||
is_control_bar_in_left_ ? (control_window_width_ + 5.0f) : 5.0f, 40.0f));
|
||||
|
||||
|
||||
@@ -2,18 +2,18 @@
|
||||
#include "render.h"
|
||||
|
||||
int Render::ControlWindow() {
|
||||
auto time_duration = ImGui::GetTime() - control_bar_button_pressed_time_;
|
||||
double time_duration = ImGui::GetTime() - control_bar_button_pressed_time_;
|
||||
if (control_window_width_is_changing_) {
|
||||
if (control_bar_expand_) {
|
||||
control_window_width_ =
|
||||
control_window_min_width_ +
|
||||
(control_window_max_width_ - control_window_min_width_) * 4 *
|
||||
time_duration;
|
||||
(float)(control_window_min_width_ +
|
||||
(control_window_max_width_ - control_window_min_width_) * 4 *
|
||||
time_duration);
|
||||
} else {
|
||||
control_window_width_ =
|
||||
control_window_max_width_ -
|
||||
(control_window_max_width_ - control_window_min_width_) * 4 *
|
||||
time_duration;
|
||||
(float)(control_window_max_width_ -
|
||||
(control_window_max_width_ - control_window_min_width_) * 4 *
|
||||
time_duration);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,14 +21,14 @@ int Render::ControlWindow() {
|
||||
if (control_window_height_is_changing_) {
|
||||
if (control_bar_expand_ && net_traffic_stats_button_pressed_) {
|
||||
control_window_height_ =
|
||||
control_window_min_height_ +
|
||||
(control_window_max_height_ - control_window_min_height_) * 4 *
|
||||
time_duration;
|
||||
(float)(control_window_min_height_ +
|
||||
(control_window_max_height_ - control_window_min_height_) *
|
||||
4 * time_duration);
|
||||
} else if (control_bar_expand_ && !net_traffic_stats_button_pressed_) {
|
||||
control_window_height_ =
|
||||
control_window_max_height_ -
|
||||
(control_window_max_height_ - control_window_min_height_) * 4 *
|
||||
time_duration;
|
||||
(float)(control_window_max_height_ -
|
||||
(control_window_max_height_ - control_window_min_height_) *
|
||||
4 * time_duration);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ int Render::ControlWindow() {
|
||||
}
|
||||
|
||||
if (reset_control_bar_pos_) {
|
||||
int new_control_window_pos_x, new_control_window_pos_y, new_cursor_pos_x,
|
||||
float new_control_window_pos_x, new_control_window_pos_y, new_cursor_pos_x,
|
||||
new_cursor_pos_y;
|
||||
|
||||
// set control window pos
|
||||
@@ -94,15 +94,16 @@ int Render::ControlWindow() {
|
||||
|
||||
if (0 != mouse_diff_control_bar_pos_x_ &&
|
||||
0 != mouse_diff_control_bar_pos_y_) {
|
||||
SDL_WarpMouseInWindow(stream_window_, new_cursor_pos_x, new_cursor_pos_y);
|
||||
SDL_WarpMouseInWindow(stream_window_, (int)new_cursor_pos_x,
|
||||
(int)new_cursor_pos_y);
|
||||
}
|
||||
reset_control_bar_pos_ = false;
|
||||
} else if (!reset_control_bar_pos_ &&
|
||||
ImGui::IsMouseReleased(ImGuiPopupFlags_MouseButtonLeft) ||
|
||||
control_window_width_is_changing_) {
|
||||
if (control_winodw_pos_.x <= stream_window_width_ / 2) {
|
||||
int pos_x = 0;
|
||||
int pos_y =
|
||||
float pos_x = 0;
|
||||
float pos_y =
|
||||
(control_winodw_pos_.y >=
|
||||
(fullscreen_button_pressed_ ? 0 : (title_bar_height_ + 1)) &&
|
||||
control_winodw_pos_.y <=
|
||||
@@ -133,8 +134,8 @@ int Render::ControlWindow() {
|
||||
ImGui::SetNextWindowPos(ImVec2(pos_x, pos_y), ImGuiCond_Always);
|
||||
is_control_bar_in_left_ = true;
|
||||
} else if (control_winodw_pos_.x > stream_window_width_ / 2) {
|
||||
int pos_x = 0;
|
||||
int pos_y =
|
||||
float pos_x = 0;
|
||||
float pos_y =
|
||||
(control_winodw_pos_.y >=
|
||||
(fullscreen_button_pressed_ ? 0 : (title_bar_height_ + 1)) &&
|
||||
control_winodw_pos_.y <=
|
||||
@@ -195,7 +196,7 @@ int Render::ControlWindow() {
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
control_winodw_pos_ = ImGui::GetWindowPos();
|
||||
SDL_GetMouseState(&mouse_pos_x_, &mouse_pos_y_);
|
||||
SDL_GetMouseState(&(int)mouse_pos_x_, &(int)mouse_pos_y_);
|
||||
mouse_diff_control_bar_pos_x_ = mouse_pos_x_ - control_winodw_pos_.x;
|
||||
mouse_diff_control_bar_pos_y_ = mouse_pos_y_ - control_winodw_pos_.y;
|
||||
|
||||
|
||||
@@ -31,8 +31,8 @@ int Render::LocalWindow() {
|
||||
ImVec2(main_child_window_x_padding_,
|
||||
title_bar_height_ + main_child_window_y_padding_),
|
||||
ImGuiCond_Always);
|
||||
ImGui::PushStyleColor(ImGuiCol_ChildBg,
|
||||
ImVec4(239.0 / 255, 240.0 / 255, 242.0 / 255, 1.0f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(239.0f / 255, 240.0f / 255,
|
||||
242.0f / 255, 1.0f));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 10.0f);
|
||||
ImGui::BeginChild(
|
||||
"LocalDesktopWindow_1",
|
||||
@@ -82,7 +82,7 @@ int Render::LocalWindow() {
|
||||
ImGui::SetWindowFontScale(1.0f);
|
||||
ImGui::PopStyleColor(3);
|
||||
|
||||
auto time_duration = ImGui::GetTime() - copy_start_time_;
|
||||
double time_duration = ImGui::GetTime() - copy_start_time_;
|
||||
if (local_id_copied_ && time_duration < 1.0f) {
|
||||
const ImGuiViewport *viewport = ImGui::GetMainViewport();
|
||||
ImGui::SetNextWindowPos(
|
||||
@@ -95,8 +95,9 @@ int Render::LocalWindow() {
|
||||
|
||||
ImGui::SetNextWindowSize(
|
||||
ImVec2(notification_window_width_, notification_window_height_));
|
||||
ImGui::PushStyleColor(ImGuiCol_WindowBg,
|
||||
ImVec4(1.0, 1.0, 1.0, 1.0 - time_duration));
|
||||
ImGui::PushStyleColor(
|
||||
ImGuiCol_WindowBg,
|
||||
ImVec4(1.0f, 1.0f, 1.0f, 1.0f - (float)time_duration));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 5.0f);
|
||||
ImGui::Begin("ConnectionStatusWindow", nullptr,
|
||||
@@ -114,7 +115,7 @@ int Render::LocalWindow() {
|
||||
ImGui::SetCursorPosX((window_width - text_width) * 0.5f);
|
||||
ImGui::SetCursorPosY(window_height * 0.5f);
|
||||
ImGui::PushStyleColor(ImGuiCol_Text,
|
||||
ImVec4(0, 0, 0, 1.0 - time_duration));
|
||||
ImVec4(0, 0, 0, 1.0f - (float)time_duration));
|
||||
ImGui::Text("%s", text.c_str());
|
||||
ImGui::PopStyleColor();
|
||||
ImGui::SetWindowFontScale(1.0f);
|
||||
@@ -137,18 +138,20 @@ int Render::LocalWindow() {
|
||||
if (!password_inited_) {
|
||||
char a[] = {
|
||||
"123456789QWERTYUPASDFGHJKLZXCVBNMqwertyupasdfghijkzxcvbnm"};
|
||||
std::mt19937 generator(
|
||||
std::chrono::system_clock::now().time_since_epoch().count());
|
||||
std::uniform_int_distribution<int> distribution(0, strlen(a) - 1);
|
||||
std::mt19937 generator((unsigned int)std::chrono::system_clock::now()
|
||||
.time_since_epoch()
|
||||
.count());
|
||||
std::uniform_int_distribution<int> distribution(0,
|
||||
(int)(strlen(a) - 1));
|
||||
|
||||
random_password_.clear();
|
||||
for (int i = 0, len = strlen(a); i < 6; i++) {
|
||||
for (int i = 0; i < 6; i++) {
|
||||
random_password_ += a[distribution(generator)];
|
||||
}
|
||||
password_inited_ = true;
|
||||
if (0 != strcmp(random_password_.c_str(), password_saved_)) {
|
||||
strncpy(password_saved_, random_password_.c_str(),
|
||||
sizeof(password_saved_));
|
||||
memcpy(password_saved_, random_password_.c_str(),
|
||||
sizeof(password_saved_));
|
||||
LOG_INFO("Generate new password and save into cache file");
|
||||
SaveSettingsIntoCacheFile();
|
||||
}
|
||||
@@ -279,7 +282,7 @@ int Render::LocalWindow() {
|
||||
} else {
|
||||
show_reset_password_window_ = false;
|
||||
LOG_INFO("Generate new password and save into cache file");
|
||||
strncpy(password_saved_, new_password_, sizeof(password_saved_));
|
||||
memcpy(password_saved_, new_password_, sizeof(password_saved_));
|
||||
memset(new_password_, 0, sizeof(new_password_));
|
||||
SaveSettingsIntoCacheFile();
|
||||
LeaveConnection(peer_, client_id_);
|
||||
|
||||
@@ -38,12 +38,12 @@ int Render::ShowRecentConnections() {
|
||||
ImGui::SetCursorPosX(25.0f);
|
||||
ImVec2 sub_window_pos = ImGui::GetCursorPos();
|
||||
std::map<std::string, ImVec2> sub_containers_pos;
|
||||
int recent_connection_sub_container_width =
|
||||
float recent_connection_sub_container_width =
|
||||
recent_connection_image_width_ + 16.0f;
|
||||
int recent_connection_sub_container_height =
|
||||
float recent_connection_sub_container_height =
|
||||
recent_connection_image_height_ + 36.0f;
|
||||
ImGui::PushStyleColor(ImGuiCol_ChildBg,
|
||||
ImVec4(239.0 / 255, 240.0 / 255, 242.0 / 255, 1.0f));
|
||||
ImVec4(239.0f / 255, 240.0f / 255, 242.0f / 255, 1.0f));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 10.0f);
|
||||
ImGui::BeginChild("RecentConnectionsContainer",
|
||||
ImVec2(main_window_width_default_ - 50.0f, 145.0f),
|
||||
@@ -56,10 +56,10 @@ int Render::ShowRecentConnections() {
|
||||
ImGuiWindowFlags_NoScrollWithMouse);
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::PopStyleColor();
|
||||
int recent_connections_count = recent_connection_textures_.size();
|
||||
size_t recent_connections_count = recent_connection_textures_.size();
|
||||
int count = 0;
|
||||
int button_width = 22;
|
||||
int button_height = 22;
|
||||
float button_width = 22;
|
||||
float button_height = 22;
|
||||
for (auto it = recent_connection_textures_.begin();
|
||||
it != recent_connection_textures_.end(); ++it) {
|
||||
sub_containers_pos[it->first] = ImGui::GetCursorPos();
|
||||
@@ -180,7 +180,7 @@ int Render::ShowRecentConnections() {
|
||||
if (!password.empty() && password.size() == 6) {
|
||||
remember_password_ = true;
|
||||
}
|
||||
strncpy(remote_password_, password.c_str(), 6);
|
||||
memcpy(remote_password_, password.c_str(), 6);
|
||||
ConnectTo();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,8 +32,8 @@ int Render::RemoteWindow() {
|
||||
ImVec2(local_window_width_ + main_child_window_x_padding_ - 1.0f,
|
||||
title_bar_height_ + main_child_window_y_padding_),
|
||||
ImGuiCond_Always);
|
||||
ImGui::PushStyleColor(ImGuiCol_ChildBg,
|
||||
ImVec4(239.0 / 255, 240.0 / 255, 242.0 / 255, 1.0f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(239.0f / 255, 240.0f / 255,
|
||||
242.0f / 255, 1.0f));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 10.0f);
|
||||
|
||||
ImGui::BeginChild(
|
||||
|
||||
@@ -75,16 +75,16 @@ Render::~Render() {}
|
||||
|
||||
int Render::SaveSettingsIntoCacheFile() {
|
||||
cd_cache_mutex_.lock();
|
||||
std::ofstream cd_cache_file_("cache.cd", std::ios::binary);
|
||||
if (!cd_cache_file_) {
|
||||
std::ofstream cd_cache_file("cache.cd", std::ios::binary);
|
||||
if (!cd_cache_file) {
|
||||
cd_cache_mutex_.unlock();
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&cd_cache_.client_id, 0, sizeof(cd_cache_.client_id));
|
||||
strncpy(cd_cache_.client_id, client_id_, sizeof(client_id_));
|
||||
memcpy(cd_cache_.client_id, client_id_, sizeof(client_id_));
|
||||
memset(&cd_cache_.password, 0, sizeof(cd_cache_.password));
|
||||
strncpy(cd_cache_.password, password_saved_, sizeof(password_saved_));
|
||||
memcpy(cd_cache_.password, password_saved_, sizeof(password_saved_));
|
||||
memcpy(&cd_cache_.language, &language_button_value_,
|
||||
sizeof(language_button_value_));
|
||||
memcpy(&cd_cache_.video_quality, &video_quality_button_value_,
|
||||
@@ -95,8 +95,8 @@ int Render::SaveSettingsIntoCacheFile() {
|
||||
sizeof(enable_hardware_video_codec_));
|
||||
memcpy(&cd_cache_.enable_turn, &enable_turn_, sizeof(enable_turn_));
|
||||
|
||||
cd_cache_file_.write(reinterpret_cast<char*>(&cd_cache_), sizeof(CDCache));
|
||||
cd_cache_file_.close();
|
||||
cd_cache_file.write(reinterpret_cast<char*>(&cd_cache_), sizeof(CDCache));
|
||||
cd_cache_file.close();
|
||||
cd_cache_mutex_.unlock();
|
||||
|
||||
config_center_.SetLanguage((ConfigCenter::LANGUAGE)language_button_value_);
|
||||
@@ -114,8 +114,8 @@ int Render::SaveSettingsIntoCacheFile() {
|
||||
|
||||
int Render::LoadSettingsFromCacheFile() {
|
||||
cd_cache_mutex_.lock();
|
||||
std::ifstream cd_cache_file_("cache.cd", std::ios::binary);
|
||||
if (!cd_cache_file_) {
|
||||
std::ifstream cd_cache_file("cache.cd", std::ios::binary);
|
||||
if (!cd_cache_file) {
|
||||
cd_cache_mutex_.unlock();
|
||||
|
||||
LOG_INFO("Init cache file by using default settings");
|
||||
@@ -145,13 +145,13 @@ int Render::LoadSettingsFromCacheFile() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
cd_cache_file_.read(reinterpret_cast<char*>(&cd_cache_), sizeof(CDCache));
|
||||
cd_cache_file_.close();
|
||||
cd_cache_file.read(reinterpret_cast<char*>(&cd_cache_), sizeof(CDCache));
|
||||
cd_cache_file.close();
|
||||
cd_cache_mutex_.unlock();
|
||||
|
||||
memset(&client_id_, 0, sizeof(client_id_));
|
||||
strncpy(client_id_, cd_cache_.client_id, sizeof(client_id_));
|
||||
strncpy(password_saved_, cd_cache_.password, sizeof(password_saved_));
|
||||
memcpy(client_id_, cd_cache_.client_id, sizeof(client_id_));
|
||||
memcpy(password_saved_, cd_cache_.password, sizeof(password_saved_));
|
||||
if (0 != strcmp(password_saved_, "") && 7 == sizeof(password_saved_)) {
|
||||
password_inited_ = true;
|
||||
}
|
||||
@@ -365,7 +365,7 @@ int Render::CreateConnectionPeer() {
|
||||
|
||||
int Render::AudioDeviceInit() {
|
||||
// Audio
|
||||
SDL_AudioSpec want_in, have_in, want_out, have_out;
|
||||
SDL_AudioSpec want_in, want_out;
|
||||
SDL_zero(want_in);
|
||||
want_in.freq = 48000;
|
||||
want_in.format = AUDIO_S16LSB;
|
||||
@@ -453,12 +453,12 @@ int Render::CreateMainWindow() {
|
||||
|
||||
ImGui::SetCurrentContext(main_ctx_);
|
||||
|
||||
SDL_WindowFlags window_flags =
|
||||
(SDL_WindowFlags)(SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_BORDERLESS |
|
||||
SDL_WINDOW_HIDDEN);
|
||||
main_window_ = SDL_CreateWindow(
|
||||
"Remote Desk", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||
main_window_width_default_, main_window_height_default_, window_flags);
|
||||
SDL_WindowFlags window_flags = (SDL_WindowFlags)(
|
||||
SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_BORDERLESS | SDL_WINDOW_HIDDEN);
|
||||
main_window_ =
|
||||
SDL_CreateWindow("Remote Desk", SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL_WINDOWPOS_UNDEFINED, (int)main_window_width_default_,
|
||||
(int)main_window_height_default_, window_flags);
|
||||
|
||||
main_renderer_ = SDL_CreateRenderer(
|
||||
main_window_, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
|
||||
@@ -506,10 +506,10 @@ int Render::CreateStreamWindow() {
|
||||
|
||||
SDL_WindowFlags window_flags =
|
||||
(SDL_WindowFlags)(SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_BORDERLESS);
|
||||
stream_window_ =
|
||||
SDL_CreateWindow("Stream window", SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL_WINDOWPOS_UNDEFINED, stream_window_width_default_,
|
||||
stream_window_height_default_, window_flags);
|
||||
stream_window_ = SDL_CreateWindow(
|
||||
"Stream window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||
(int)stream_window_width_default_, (int)stream_window_height_default_,
|
||||
window_flags);
|
||||
|
||||
stream_renderer_ = SDL_CreateRenderer(
|
||||
stream_window_, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
|
||||
@@ -551,7 +551,7 @@ int Render::DestroyStreamWindow() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Render::SetupFontAndStyle(bool is_main_window) {
|
||||
int Render::SetupFontAndStyle() {
|
||||
// Setup Dear ImGui style
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.ConfigFlags |=
|
||||
@@ -583,14 +583,12 @@ int Render::SetupMainWindow() {
|
||||
|
||||
ImGui::SetCurrentContext(main_ctx_);
|
||||
|
||||
SetupFontAndStyle(true);
|
||||
SetupFontAndStyle();
|
||||
|
||||
SDL_GL_GetDrawableSize(main_window_, &main_window_width_real_,
|
||||
&main_window_height_real_);
|
||||
main_window_dpi_scaling_w_ =
|
||||
(float)main_window_width_real_ / (float)main_window_width_;
|
||||
main_window_dpi_scaling_h_ =
|
||||
(float)main_window_width_real_ / (float)main_window_width_;
|
||||
main_window_dpi_scaling_w_ = main_window_width_real_ / main_window_width_;
|
||||
main_window_dpi_scaling_h_ = main_window_width_real_ / main_window_width_;
|
||||
SDL_RenderSetScale(main_renderer_, main_window_dpi_scaling_w_,
|
||||
main_window_dpi_scaling_h_);
|
||||
LOG_INFO("Use dpi scaling [{}x{}] for main window",
|
||||
@@ -623,14 +621,14 @@ int Render::SetupStreamWindow() {
|
||||
|
||||
ImGui::SetCurrentContext(stream_ctx_);
|
||||
|
||||
SetupFontAndStyle(false);
|
||||
SetupFontAndStyle();
|
||||
|
||||
SDL_GL_GetDrawableSize(stream_window_, &stream_window_width_real_,
|
||||
&stream_window_height_real_);
|
||||
SDL_GL_GetDrawableSize(stream_window_, &main_window_width_real_,
|
||||
&main_window_height_real_);
|
||||
stream_window_dpi_scaling_w_ =
|
||||
(float)stream_window_width_real_ / (float)stream_window_width_;
|
||||
stream_window_width_real_ / stream_window_width_;
|
||||
stream_window_dpi_scaling_h_ =
|
||||
(float)stream_window_width_real_ / (float)stream_window_width_;
|
||||
stream_window_width_real_ / stream_window_width_;
|
||||
SDL_RenderSetScale(stream_renderer_, stream_window_dpi_scaling_w_,
|
||||
stream_window_dpi_scaling_h_);
|
||||
LOG_INFO("Use dpi scaling [{}x{}] for stream window",
|
||||
@@ -758,9 +756,9 @@ int Render::Run() {
|
||||
screen_height_ = DM.h;
|
||||
|
||||
stream_render_rect_.x = 0;
|
||||
stream_render_rect_.y = title_bar_height_;
|
||||
stream_render_rect_.w = stream_window_width_;
|
||||
stream_render_rect_.h = stream_window_height_ - title_bar_height_;
|
||||
stream_render_rect_.y = (int)title_bar_height_;
|
||||
stream_render_rect_.w = (int)stream_window_width_;
|
||||
stream_render_rect_.h = (int)(stream_window_height_ - title_bar_height_);
|
||||
|
||||
// use linear filtering to render textures otherwise the graphics will be
|
||||
// blurry
|
||||
@@ -885,8 +883,8 @@ int Render::Run() {
|
||||
memset(&net_traffic_stats_, 0, sizeof(net_traffic_stats_));
|
||||
SDL_SetWindowFullscreen(main_window_, SDL_FALSE);
|
||||
memset(audio_buffer_, 0, 720);
|
||||
SDL_SetWindowSize(main_window_, main_window_width_default_,
|
||||
main_window_height_default_);
|
||||
SDL_SetWindowSize(main_window_, (int)main_window_width_default_,
|
||||
(int)main_window_height_default_);
|
||||
|
||||
// SDL_Rect display_bounds;
|
||||
// SDL_GetDisplayBounds(0, &display_bounds);
|
||||
@@ -905,14 +903,14 @@ int Render::Run() {
|
||||
window_maximized_ = false;
|
||||
} else if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
|
||||
reset_control_bar_pos_ = true;
|
||||
SDL_GetWindowSize(stream_window_, &stream_window_width_,
|
||||
&stream_window_height_);
|
||||
SDL_GetWindowSize(stream_window_, &((int)stream_window_width_),
|
||||
&((int)stream_window_height_));
|
||||
|
||||
float video_ratio = (float)video_width_ / (float)video_height_;
|
||||
float video_ratio_reverse = (float)video_height_ / (float)video_width_;
|
||||
|
||||
int render_area_width = stream_window_width_;
|
||||
int render_area_height =
|
||||
float render_area_width = stream_window_width_;
|
||||
float render_area_height =
|
||||
stream_window_height_ -
|
||||
(fullscreen_button_pressed_ ? 0 : title_bar_height_);
|
||||
|
||||
@@ -920,25 +918,27 @@ int Render::Run() {
|
||||
if (render_area_width < render_area_height * video_ratio) {
|
||||
stream_render_rect_.x = 0;
|
||||
stream_render_rect_.y =
|
||||
abs(render_area_height -
|
||||
render_area_width * video_ratio_reverse) /
|
||||
2 +
|
||||
(fullscreen_button_pressed_ ? 0 : title_bar_height_);
|
||||
stream_render_rect_.w = render_area_width;
|
||||
stream_render_rect_.h = render_area_width * video_ratio_reverse;
|
||||
(int)(abs(render_area_height -
|
||||
render_area_width * video_ratio_reverse) /
|
||||
2 +
|
||||
(fullscreen_button_pressed_ ? 0 : title_bar_height_));
|
||||
stream_render_rect_.w = (int)render_area_width;
|
||||
stream_render_rect_.h =
|
||||
(int)(render_area_width * video_ratio_reverse);
|
||||
} else if (render_area_width > render_area_height * video_ratio) {
|
||||
stream_render_rect_.x =
|
||||
abs(render_area_width - render_area_height * video_ratio) / 2;
|
||||
(int)abs(render_area_width - render_area_height * video_ratio) /
|
||||
2;
|
||||
stream_render_rect_.y =
|
||||
fullscreen_button_pressed_ ? 0 : title_bar_height_;
|
||||
stream_render_rect_.w = render_area_height * video_ratio;
|
||||
stream_render_rect_.h = render_area_height;
|
||||
fullscreen_button_pressed_ ? 0 : (int)title_bar_height_;
|
||||
stream_render_rect_.w = (int)(render_area_height * video_ratio);
|
||||
stream_render_rect_.h = (int)render_area_height;
|
||||
} else {
|
||||
stream_render_rect_.x = 0;
|
||||
stream_render_rect_.y =
|
||||
fullscreen_button_pressed_ ? 0 : title_bar_height_;
|
||||
stream_render_rect_.w = render_area_width;
|
||||
stream_render_rect_.h = render_area_height;
|
||||
fullscreen_button_pressed_ ? 0 : (int)title_bar_height_;
|
||||
stream_render_rect_.w = (int)render_area_width;
|
||||
stream_render_rect_.h = (int)render_area_height;
|
||||
}
|
||||
} else if (event.type == SDL_WINDOWEVENT &&
|
||||
event.window.event == SDL_WINDOWEVENT_CLOSE) {
|
||||
|
||||
@@ -57,7 +57,7 @@ class Render {
|
||||
int DestroyMainWindow();
|
||||
int CreateStreamWindow();
|
||||
int DestroyStreamWindow();
|
||||
int SetupFontAndStyle(bool is_main_window);
|
||||
int SetupFontAndStyle();
|
||||
int SetupMainWindow();
|
||||
int DestroyMainWindowContext();
|
||||
int SetupStreamWindow();
|
||||
@@ -65,7 +65,7 @@ class Render {
|
||||
int DrawMainWindow();
|
||||
int DrawStreamWindow();
|
||||
int ConfirmDeleteConnection();
|
||||
int NetTrafficStats(ImVec2 mouse_button_pos);
|
||||
int NetTrafficStats();
|
||||
|
||||
public:
|
||||
static void OnReceiveVideoBufferCb(const XVideoFrame *video_frame,
|
||||
@@ -139,7 +139,6 @@ class Render {
|
||||
} CDCache;
|
||||
|
||||
private:
|
||||
std::ifstream cd_cache_file_;
|
||||
CDCache cd_cache_;
|
||||
std::mutex cd_cache_mutex_;
|
||||
|
||||
@@ -171,57 +170,57 @@ class Render {
|
||||
char client_password_[20] = "";
|
||||
|
||||
private:
|
||||
int title_bar_width_ = 640;
|
||||
int title_bar_height_ = 30;
|
||||
float title_bar_width_ = 640;
|
||||
float title_bar_height_ = 30;
|
||||
int screen_width_ = 1280;
|
||||
int screen_height_ = 720;
|
||||
int main_window_width_default_ = 640;
|
||||
int main_window_height_default_ = 480;
|
||||
int main_window_width_ = 640;
|
||||
int main_window_height_ = 480;
|
||||
int main_window_width_last_ = 640;
|
||||
int main_window_height_last_ = 480;
|
||||
int stream_window_width_default_ = 1280;
|
||||
int stream_window_height_default_ = 720;
|
||||
int stream_window_width_ = 1280;
|
||||
int stream_window_height_ = 720;
|
||||
float main_window_width_default_ = 640;
|
||||
float main_window_height_default_ = 480;
|
||||
float main_window_width_ = 640;
|
||||
float main_window_height_ = 480;
|
||||
float main_window_width_last_ = 640;
|
||||
float main_window_height_last_ = 480;
|
||||
float stream_window_width_default_ = 1280;
|
||||
float stream_window_height_default_ = 720;
|
||||
float stream_window_width_ = 1280;
|
||||
float stream_window_height_ = 720;
|
||||
int stream_window_width_last_ = 1280;
|
||||
int stream_window_height_last_ = 720;
|
||||
int stream_window_width_before_maximized_ = 1280;
|
||||
int stream_window_height_before_maximized_ = 720;
|
||||
int control_window_min_width_ = 20;
|
||||
int control_window_max_width_ = 200;
|
||||
int control_window_min_height_ = 40;
|
||||
int control_window_max_height_ = 150;
|
||||
int control_window_width_ = 200;
|
||||
int control_window_height_ = 40;
|
||||
int local_window_width_ = 320;
|
||||
int local_window_height_ = 235;
|
||||
int remote_window_width_ = 320;
|
||||
int remote_window_height_ = 235;
|
||||
int local_child_window_width_ = 266;
|
||||
int local_child_window_height_ = 180;
|
||||
int remote_child_window_width_ = 266;
|
||||
int remote_child_window_height_ = 180;
|
||||
int main_window_text_y_padding_ = 10;
|
||||
int main_child_window_x_padding_ = 27;
|
||||
int main_child_window_y_padding_ = 45;
|
||||
int status_bar_height_ = 22;
|
||||
int connection_status_window_width_ = 200;
|
||||
int connection_status_window_height_ = 150;
|
||||
int notification_window_width_ = 200;
|
||||
int notification_window_height_ = 80;
|
||||
int about_window_width_ = 200;
|
||||
int about_window_height_ = 150;
|
||||
float stream_window_width_before_maximized_ = 1280;
|
||||
float stream_window_height_before_maximized_ = 720;
|
||||
float control_window_min_width_ = 20;
|
||||
float control_window_max_width_ = 200;
|
||||
float control_window_min_height_ = 40;
|
||||
float control_window_max_height_ = 150;
|
||||
float control_window_width_ = 200;
|
||||
float control_window_height_ = 40;
|
||||
float local_window_width_ = 320;
|
||||
float local_window_height_ = 235;
|
||||
float remote_window_width_ = 320;
|
||||
float remote_window_height_ = 235;
|
||||
float local_child_window_width_ = 266;
|
||||
float local_child_window_height_ = 180;
|
||||
float remote_child_window_width_ = 266;
|
||||
float remote_child_window_height_ = 180;
|
||||
float main_window_text_y_padding_ = 10;
|
||||
float main_child_window_x_padding_ = 27;
|
||||
float main_child_window_y_padding_ = 45;
|
||||
float status_bar_height_ = 22;
|
||||
float connection_status_window_width_ = 200;
|
||||
float connection_status_window_height_ = 150;
|
||||
float notification_window_width_ = 200;
|
||||
float notification_window_height_ = 80;
|
||||
float about_window_width_ = 200;
|
||||
float about_window_height_ = 150;
|
||||
|
||||
int control_bar_pos_x_ = 0;
|
||||
int control_bar_pos_y_ = 30;
|
||||
int mouse_diff_control_bar_pos_x_ = 0;
|
||||
int mouse_diff_control_bar_pos_y_ = 0;
|
||||
int mouse_pos_x_ = 0;
|
||||
int mouse_pos_y_ = 0;
|
||||
int mouse_pos_x_last_ = 0;
|
||||
int mouse_pos_y_last_ = 0;
|
||||
float control_bar_pos_x_ = 0;
|
||||
float control_bar_pos_y_ = 30;
|
||||
float mouse_diff_control_bar_pos_x_ = 0;
|
||||
float mouse_diff_control_bar_pos_y_ = 0;
|
||||
float mouse_pos_x_ = 0;
|
||||
float mouse_pos_y_ = 0;
|
||||
float mouse_pos_x_last_ = 0;
|
||||
float mouse_pos_y_last_ = 0;
|
||||
|
||||
int main_window_width_real_ = 720;
|
||||
int main_window_height_real_ = 540;
|
||||
@@ -238,7 +237,7 @@ class Render {
|
||||
|
||||
int video_width_ = 1280;
|
||||
int video_height_ = 720;
|
||||
int video_size_ = 1280 * 720 * 3;
|
||||
size_t video_size_ = 1280 * 720 * 3;
|
||||
|
||||
SDL_Window *main_window_ = nullptr;
|
||||
SDL_Renderer *main_renderer_ = nullptr;
|
||||
@@ -346,7 +345,7 @@ class Render {
|
||||
unsigned char audio_buffer_[720];
|
||||
int audio_len_ = 0;
|
||||
unsigned char *dst_buffer_ = nullptr;
|
||||
int dst_buffer_capacity_ = 0;
|
||||
size_t dst_buffer_capacity_ = 0;
|
||||
|
||||
private:
|
||||
ScreenCapturerFactory *screen_capturer_factory_ = nullptr;
|
||||
@@ -356,7 +355,7 @@ class Render {
|
||||
DeviceControllerFactory *device_controller_factory_ = nullptr;
|
||||
MouseController *mouse_controller_ = nullptr;
|
||||
KeyboardCapturer *keyboard_capturer_ = nullptr;
|
||||
uint32_t last_frame_time_;
|
||||
uint64_t last_frame_time_;
|
||||
|
||||
private:
|
||||
char client_id_[10] = "";
|
||||
|
||||
@@ -124,7 +124,9 @@ void Render::SdlCaptureAudioIn(void *userdata, Uint8 *stream, int len) {
|
||||
}
|
||||
}
|
||||
|
||||
void Render::SdlCaptureAudioOut(void *userdata, Uint8 *stream, int len) {
|
||||
void Render::SdlCaptureAudioOut([[maybe_unused]] void *userdata,
|
||||
[[maybe_unused]] Uint8 *stream,
|
||||
[[maybe_unused]] int len) {
|
||||
// Render *render = (Render *)userdata;
|
||||
// if ("Connected" == render->connection_status_str_) {
|
||||
// SendAudioFrame(render->peer_, (const char *)stream, len);
|
||||
@@ -148,7 +150,8 @@ void Render::SdlCaptureAudioOut(void *userdata, Uint8 *stream, int len) {
|
||||
}
|
||||
|
||||
void Render::OnReceiveVideoBufferCb(const XVideoFrame *video_frame,
|
||||
const char *user_id, size_t user_id_size,
|
||||
[[maybe_unused]] const char *user_id,
|
||||
[[maybe_unused]] size_t user_id_size,
|
||||
void *user_data) {
|
||||
Render *render = (Render *)user_data;
|
||||
if (!render) {
|
||||
@@ -186,7 +189,8 @@ void Render::OnReceiveVideoBufferCb(const XVideoFrame *video_frame,
|
||||
}
|
||||
|
||||
void Render::OnReceiveAudioBufferCb(const char *data, size_t size,
|
||||
const char *user_id, size_t user_id_size,
|
||||
[[maybe_unused]] const char *user_id,
|
||||
[[maybe_unused]] size_t user_id_size,
|
||||
void *user_data) {
|
||||
Render *render = (Render *)user_data;
|
||||
if (!render) {
|
||||
@@ -207,7 +211,7 @@ void Render::OnReceiveDataBufferCb(const char *data, size_t size,
|
||||
|
||||
std::string user(user_id, user_id_size);
|
||||
RemoteAction remote_action;
|
||||
memcpy(&remote_action, data, sizeof(remote_action));
|
||||
memcpy(&remote_action, data, size);
|
||||
|
||||
if (ControlType::mouse == remote_action.type && render->mouse_controller_) {
|
||||
render->mouse_controller_->SendCommand(remote_action);
|
||||
@@ -218,7 +222,8 @@ void Render::OnReceiveDataBufferCb(const char *data, size_t size,
|
||||
render->StopSpeakerCapturer();
|
||||
}
|
||||
} else if (ControlType::keyboard == remote_action.type) {
|
||||
render->ProcessKeyEvent(remote_action.k.key_value, remote_action.k.flag);
|
||||
render->ProcessKeyEvent((int)remote_action.k.key_value,
|
||||
remote_action.k.flag);
|
||||
} else if (ControlType::host_infomation == remote_action.type) {
|
||||
render->host_name_ =
|
||||
std::string(remote_action.i.host_name, remote_action.i.host_name_size);
|
||||
@@ -255,8 +260,10 @@ void Render::OnSignalStatusCb(SignalStatus status, void *user_data) {
|
||||
}
|
||||
}
|
||||
|
||||
void Render::OnConnectionStatusCb(ConnectionStatus status, const char *user_id,
|
||||
const size_t user_id_size, void *user_data) {
|
||||
void Render::OnConnectionStatusCb(ConnectionStatus status,
|
||||
[[maybe_unused]] const char *user_id,
|
||||
[[maybe_unused]] const size_t user_id_size,
|
||||
void *user_data) {
|
||||
Render *render = (Render *)user_data;
|
||||
if (!render) {
|
||||
return;
|
||||
@@ -352,7 +359,7 @@ void Render::NetStatusReport(const char *client_id, size_t client_id_size,
|
||||
|
||||
if (0 == strcmp(render->client_id_, "")) {
|
||||
memset(&render->client_id_, 0, sizeof(render->client_id_));
|
||||
strncpy(render->client_id_, client_id, client_id_size);
|
||||
memcpy(render->client_id_, client_id, client_id_size);
|
||||
LOG_INFO("Use client id [{}] and save id into cache file", client_id);
|
||||
render->SaveSettingsIntoCacheFile();
|
||||
}
|
||||
|
||||
@@ -155,6 +155,8 @@ LICENSE
|
||||
See end of file for license information.
|
||||
|
||||
*/
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4996)
|
||||
|
||||
#ifndef INCLUDE_STB_IMAGE_WRITE_H
|
||||
#define INCLUDE_STB_IMAGE_WRITE_H
|
||||
@@ -1933,6 +1935,7 @@ STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp,
|
||||
#endif
|
||||
|
||||
#endif // STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#pragma warning(pop)
|
||||
|
||||
/* Revision history
|
||||
1.16 (2021-07-11)
|
||||
|
||||
@@ -274,7 +274,7 @@ std::string Thumbnail::AES_encrypt(const std::string& plaintext,
|
||||
ret = EVP_EncryptUpdate(
|
||||
ctx, ciphertext.data(), &len,
|
||||
reinterpret_cast<const unsigned char*>(plaintext.data()),
|
||||
plaintext.size());
|
||||
(int)plaintext.size());
|
||||
if (1 != ret) {
|
||||
LOG_ERROR("Error in EVP_EncryptUpdate");
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
@@ -339,7 +339,7 @@ std::string Thumbnail::AES_decrypt(const std::string& ciphertext,
|
||||
}
|
||||
|
||||
ret = EVP_DecryptUpdate(ctx, plaintext, &plaintext_len, ciphertext_buf,
|
||||
ciphertext_buf_len);
|
||||
(int)ciphertext_buf_len);
|
||||
if (1 != ret) {
|
||||
LOG_ERROR("Error in EVP_DecryptUpdate");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user