diff --git a/src/common/platform.cpp b/src/common/platform.cpp index eb4bc87..1dd43da 100644 --- a/src/common/platform.cpp +++ b/src/common/platform.cpp @@ -25,13 +25,13 @@ std::string GetMac() { #ifdef _WIN32 IP_ADAPTER_INFO adapterInfo[16]; DWORD bufferSize = sizeof(adapterInfo); - DWORD result = GetAdaptersInfo(adapterInfo, &bufferSize); if (result == ERROR_SUCCESS) { PIP_ADAPTER_INFO adapter = adapterInfo; while (adapter) { for (UINT i = 0; i < adapter->AddressLength; i++) { - len += sprintf(mac_addr + len, "%.2X", adapter->Address[i]); + len += sprintf_s(mac_addr + len, sizeof(mac_addr) - len, "%.2X", + adapter->Address[i]); } break; } diff --git a/src/device_controller/keyboard/windows/keyboard_capturer.cpp b/src/device_controller/keyboard/windows/keyboard_capturer.cpp index ae49bdd..f9ea758 100644 --- a/src/device_controller/keyboard/windows/keyboard_capturer.cpp +++ b/src/device_controller/keyboard/windows/keyboard_capturer.cpp @@ -45,7 +45,7 @@ int KeyboardCapturer::Unhook() { int KeyboardCapturer::SendKeyboardCommand(int key_code, bool is_down) { INPUT input = {0}; input.type = INPUT_KEYBOARD; - input.ki.wVk = key_code; + input.ki.wVk = (WORD)key_code; if (!is_down) { input.ki.dwFlags = KEYEVENTF_KEYUP; diff --git a/src/device_controller/mouse/windows/mouse_controller.cpp b/src/device_controller/mouse/windows/mouse_controller.cpp index 21776c9..5b13f27 100644 --- a/src/device_controller/mouse/windows/mouse_controller.cpp +++ b/src/device_controller/mouse/windows/mouse_controller.cpp @@ -20,8 +20,8 @@ int MouseController::SendCommand(RemoteAction remote_action) { if (remote_action.type == ControlType::mouse) { ip.type = INPUT_MOUSE; - ip.mi.dx = remote_action.m.x; - ip.mi.dy = remote_action.m.y; + ip.mi.dx = (LONG)remote_action.m.x; + ip.mi.dy = (LONG)remote_action.m.y; if (remote_action.m.flag == MouseFlag::left_down) { ip.mi.dwFlags = MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE; } else if (remote_action.m.flag == MouseFlag::left_up) { diff --git a/src/gui/main.cpp b/src/gui/main.cpp index 8e595cb..59dfc83 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -9,7 +9,7 @@ #include "rd_log.h" #include "render.h" -int main(int argc, char *argv[]) { +int main([[maybe_unused]] int argc, [[maybe_unused]] char *argv[]) { LOG_INFO("Remote desk"); Render render; diff --git a/src/log/rd_log.cpp b/src/log/rd_log.cpp index 6b01b48..55ae6de 100644 --- a/src/log/rd_log.cpp +++ b/src/log/rd_log.cpp @@ -6,12 +6,20 @@ std::shared_ptr get_logger() { } auto now = std::chrono::system_clock::now() + std::chrono::hours(8); - auto timet = std::chrono::system_clock::to_time_t(now); - auto localTime = *std::gmtime(&timet); + auto now_time = std::chrono::system_clock::to_time_t(now); + + std::tm tm_info; + +#ifdef _WIN32 + gmtime_s(&tm_info, &now_time); +#else + gmtime_r(&now_time, &tm_info); +#endif + std::stringstream ss; std::string filename; ss << LOGGER_NAME; - ss << std::put_time(&localTime, "-%Y%m%d-%H%M%S.log"); + ss << std::put_time(&tm_info, "-%Y%m%d-%H%M%S.log"); ss >> filename; std::string path = "logs/" + filename; diff --git a/src/screen_capturer/windows/screen_capturer_wgc.cpp b/src/screen_capturer/windows/screen_capturer_wgc.cpp index e3f855f..7c824cf 100644 --- a/src/screen_capturer/windows/screen_capturer_wgc.cpp +++ b/src/screen_capturer/windows/screen_capturer_wgc.cpp @@ -9,8 +9,8 @@ #include "libyuv.h" -BOOL WINAPI EnumMonitorProc(HMONITOR hmonitor, HDC hdc, LPRECT lprc, - LPARAM data) { +BOOL WINAPI EnumMonitorProc(HMONITOR hmonitor, [[maybe_unused]] HDC hdc, + [[maybe_unused]] LPRECT lprc, LPARAM data) { MONITORINFOEX info_ex; info_ex.cbSize = sizeof(MONITORINFOEX); diff --git a/src/screen_capturer/windows/wgc_session_impl.cpp b/src/screen_capturer/windows/wgc_session_impl.cpp index 616d8f8..29663ce 100644 --- a/src/screen_capturer/windows/wgc_session_impl.cpp +++ b/src/screen_capturer/windows/wgc_session_impl.cpp @@ -148,7 +148,7 @@ auto WgcSessionImpl::CreateD3D11Device() { if (DXGI_ERROR_UNSUPPORTED == hr) { // change D3D_DRIVER_TYPE - D3D_DRIVER_TYPE type = D3D_DRIVER_TYPE_WARP; + type = D3D_DRIVER_TYPE_WARP; hr = D3D11CreateDevice(nullptr, type, nullptr, flags, nullptr, 0, D3D11_SDK_VERSION, d3d_device.put(), nullptr, nullptr); @@ -213,7 +213,7 @@ HRESULT WgcSessionImpl::CreateMappedTexture( void WgcSessionImpl::OnFrame( winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool const &sender, - winrt::Windows::Foundation::IInspectable const &args) { + [[maybe_unused]] winrt::Windows::Foundation::IInspectable const &args) { std::lock_guard locker(lock_); auto is_new_size = false; diff --git a/src/single_window/control_bar.cpp b/src/single_window/control_bar.cpp index 95bb8fc..669f9fe 100644 --- a/src/single_window/control_bar.cpp +++ b/src/single_window/control_bar.cpp @@ -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)); diff --git a/src/single_window/control_window.cpp b/src/single_window/control_window.cpp index 4851788..1f107ba 100644 --- a/src/single_window/control_window.cpp +++ b/src/single_window/control_window.cpp @@ -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; diff --git a/src/single_window/local_peer_window.cpp b/src/single_window/local_peer_window.cpp index 8a833a9..9d2dab6 100644 --- a/src/single_window/local_peer_window.cpp +++ b/src/single_window/local_peer_window.cpp @@ -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 distribution(0, strlen(a) - 1); + std::mt19937 generator((unsigned int)std::chrono::system_clock::now() + .time_since_epoch() + .count()); + std::uniform_int_distribution 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_); diff --git a/src/single_window/recent_connections.cpp b/src/single_window/recent_connections.cpp index f72c650..22717ea 100644 --- a/src/single_window/recent_connections.cpp +++ b/src/single_window/recent_connections.cpp @@ -38,12 +38,12 @@ int Render::ShowRecentConnections() { ImGui::SetCursorPosX(25.0f); ImVec2 sub_window_pos = ImGui::GetCursorPos(); std::map 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(); } } diff --git a/src/single_window/remote_peer_window.cpp b/src/single_window/remote_peer_window.cpp index 44ab25d..957a77f 100644 --- a/src/single_window/remote_peer_window.cpp +++ b/src/single_window/remote_peer_window.cpp @@ -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( diff --git a/src/single_window/render.cpp b/src/single_window/render.cpp index 5000a1b..40b983e 100644 --- a/src/single_window/render.cpp +++ b/src/single_window/render.cpp @@ -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(&cd_cache_), sizeof(CDCache)); - cd_cache_file_.close(); + cd_cache_file.write(reinterpret_cast(&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(&cd_cache_), sizeof(CDCache)); - cd_cache_file_.close(); + cd_cache_file.read(reinterpret_cast(&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) { diff --git a/src/single_window/render.h b/src/single_window/render.h index 9decef4..971ccb6 100644 --- a/src/single_window/render.h +++ b/src/single_window/render.h @@ -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] = ""; diff --git a/src/single_window/render_callback_func.cpp b/src/single_window/render_callback_func.cpp index dabd951..2b9ac09 100644 --- a/src/single_window/render_callback_func.cpp +++ b/src/single_window/render_callback_func.cpp @@ -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(); } diff --git a/src/single_window/stb_image_write.h b/src/single_window/stb_image_write.h index a82198f..6d5642a 100644 --- a/src/single_window/stb_image_write.h +++ b/src/single_window/stb_image_write.h @@ -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) diff --git a/src/single_window/thumbnail.cpp b/src/single_window/thumbnail.cpp index 87f3a34..9abfb28 100644 --- a/src/single_window/thumbnail.cpp +++ b/src/single_window/thumbnail.cpp @@ -274,7 +274,7 @@ std::string Thumbnail::AES_encrypt(const std::string& plaintext, ret = EVP_EncryptUpdate( ctx, ciphertext.data(), &len, reinterpret_cast(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"); diff --git a/thirdparty/projectx b/thirdparty/projectx index 7e3856a..826fc2d 160000 --- a/thirdparty/projectx +++ b/thirdparty/projectx @@ -1 +1 @@ -Subproject commit 7e3856a68d20807fbdcf75960b9a817933986a46 +Subproject commit 826fc2d312d475355ab17c3cfd2c046876774e4f diff --git a/xmake.lua b/xmake.lua index ef9f153..4081fc0 100644 --- a/xmake.lua +++ b/xmake.lua @@ -26,8 +26,7 @@ if is_os("windows") then add_links("Shell32", "windowsapp", "dwmapi", "User32", "kernel32", "SDL2-static", "SDL2main", "gdi32", "winmm", "setupapi", "version", "Imm32", "iphlpapi") - -- add_cxflags("/W4", "/WX") - add_cxflags("/W4") + add_cxflags("/W4", "/WX") elseif is_os("linux") then add_requires("ffmpeg 5.1.2", {system = false}) add_syslinks("pthread", "dl")