[feat] add recent connections window

This commit is contained in:
dijunkun
2024-11-06 17:28:11 +08:00
parent 19ea426efc
commit 02022bdcdf
10 changed files with 12078 additions and 1340 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -22,6 +22,8 @@ static std::vector<std::string> remote_desktop = {u8"控制远程桌面",
"Control Remote Desktop"}; "Control Remote Desktop"};
static std::vector<std::string> remote_id = {u8"对端ID", "Remote ID"}; static std::vector<std::string> remote_id = {u8"对端ID", "Remote ID"};
static std::vector<std::string> connect = {u8"连接", "Connect"}; static std::vector<std::string> connect = {u8"连接", "Connect"};
static std::vector<std::string> recent_connections = {u8"近期连接",
"Recent Connections"};
static std::vector<std::string> disconnect = {u8"断开连接", "Disconnect"}; static std::vector<std::string> disconnect = {u8"断开连接", "Disconnect"};
static std::vector<std::string> fullscreen = {u8" 全屏", " Fullscreen"}; static std::vector<std::string> fullscreen = {u8" 全屏", " Fullscreen"};
static std::vector<std::string> exit_fullscreen = {u8" 退出全屏", static std::vector<std::string> exit_fullscreen = {u8" 退出全屏",

View File

@@ -7,34 +7,42 @@
#include "render.h" #include "render.h"
int Render::LocalWindow() { int Render::LocalWindow() {
ImGui::SetNextWindowPos(ImVec2(0, title_bar_height_ + 1), ImGuiCond_Always); ImGui::SetNextWindowPos(ImVec2(-1.0f, title_bar_height_), ImGuiCond_Always);
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f); ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
ImGui::BeginChild("LocalDesktopWindow", ImGui::BeginChild("LocalDesktopWindow",
ImVec2(local_window_width_, local_window_height_), ImVec2(local_window_width_, local_window_height_),
ImGuiChildFlags_Border, ImGuiChildFlags_None,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoBringToFrontOnFocus); ImGuiWindowFlags_NoBringToFrontOnFocus);
ImGui::PopStyleColor(); ImGui::PopStyleColor();
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + main_window_text_y_padding_);
ImGui::Indent(main_child_window_x_padding_);
ImGui::SetWindowFontScale(1.0f); ImGui::SetWindowFontScale(1.0f);
ImGui::Text(
"%s", localization::local_desktop[localization_language_index_].c_str()); ImGui::TextColored(
ImVec4(0.0f, 0.0f, 0.0f, 0.5f), "%s",
localization::local_desktop[localization_language_index_].c_str());
ImGui::Spacing(); ImGui::Spacing();
{ {
ImGui::SetNextWindowPos(ImVec2(30, title_bar_height_ + 50), ImGui::SetNextWindowPos(
ImGuiCond_Always); ImVec2(main_child_window_x_padding_,
title_bar_height_ + main_child_window_y_padding_),
ImGuiCond_Always);
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImGui::PushStyleColor(ImGuiCol_ChildBg,
ImVec4(239.0 / 255, 240.0 / 255, 242.0 / 255, 1.0f)); ImVec4(239.0 / 255, 240.0 / 255, 242.0 / 255, 1.0f));
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 10.0f); ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 10.0f);
ImGui::BeginChild("LocalDesktopWindow_1", ImVec2(330, 180), ImGui::BeginChild(
ImGuiChildFlags_Border, "LocalDesktopWindow_1",
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImVec2(local_child_window_width_, local_child_window_height_),
ImGuiWindowFlags_NoTitleBar | ImGuiChildFlags_Border,
ImGuiWindowFlags_NoBringToFrontOnFocus); ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoBringToFrontOnFocus);
ImGui::PopStyleVar(); ImGui::PopStyleVar();
ImGui::PopStyleColor(); ImGui::PopStyleColor();
{ {
@@ -48,16 +56,17 @@ int Render::LocalWindow() {
ImGui::SetWindowFontScale(1.0f); ImGui::SetWindowFontScale(1.0f);
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f); ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f);
char client_id_display[12] = ""; if (strcmp(client_id_display_, client_id_)) {
for (int i = 0, j = 0; i < sizeof(client_id_); i++, j++) { for (int i = 0, j = 0; i < sizeof(client_id_); i++, j++) {
client_id_display[j] = client_id_[i]; client_id_display_[j] = client_id_[i];
if (i == 2 || i == 5) { if (i == 2 || i == 5) {
client_id_display[++j] = ' '; client_id_display_[++j] = ' ';
}
} }
} }
ImGui::InputText( ImGui::InputText(
"##local_id", client_id_display, IM_ARRAYSIZE(client_id_display), "##local_id", client_id_display_, IM_ARRAYSIZE(client_id_display_),
ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_ReadOnly); ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_ReadOnly);
ImGui::PopStyleVar(); ImGui::PopStyleVar();

View File

@@ -1,3 +1,4 @@
#include "localization.h"
#include "render.h" #include "render.h"
int Render::MainWindow() { int Render::MainWindow() {
@@ -6,10 +7,75 @@ int Render::MainWindow() {
// ImVec2(main_window_width_default_, main_window_height_default_), // ImVec2(main_window_width_default_, main_window_height_default_),
// ImGuiCond_Always); // ImGuiCond_Always);
ImGui::SetNextWindowPos(ImVec2(0, title_bar_height_), ImGuiCond_Always);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
ImGui::BeginChild("MainWindow",
ImVec2(main_window_width_default_, local_window_height_),
ImGuiChildFlags_Border,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoBringToFrontOnFocus);
ImGui::PopStyleVar();
ImGui::PopStyleColor();
LocalWindow(); LocalWindow();
ImDrawList* draw_list = ImGui::GetWindowDrawList();
draw_list->AddLine(
ImVec2(main_window_width_default_ / 2, title_bar_height_ + 25.0f),
ImVec2(main_window_width_default_ / 2, title_bar_height_ + 240.0f),
IM_COL32(0, 0, 0, 122), 1.0f);
RemoteWindow(); RemoteWindow();
ImGui::EndChild();
ImGui::SetNextWindowPos(
ImVec2(0, title_bar_height_ + local_window_height_ - 1),
ImGuiCond_Always);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 0.0f));
ImGui::BeginChild("RecentConnectionsWindow",
ImVec2(main_window_width_default_,
main_window_height_default_ - title_bar_height_ -
local_window_height_ - status_bar_height_),
ImGuiChildFlags_Border,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoBringToFrontOnFocus);
ImGui::PopStyleVar();
ImGui::PopStyleColor();
ImGui::SetCursorPosY(ImGui::GetCursorPosY() +
main_window_text_y_padding_ / 2);
ImGui::Indent(main_child_window_x_padding_);
ImGui::SetWindowFontScale(0.8f);
ImGui::TextColored(
ImVec4(0.0f, 0.0f, 0.0f, 0.5f), "%s",
localization::recent_connections[localization_language_index_].c_str());
draw_list->AddLine(
ImVec2(25.0f, title_bar_height_ + local_window_height_ + 35.0f),
ImVec2(main_window_width_default_ - 25.0f,
title_bar_height_ + local_window_height_ + 35.0f),
IM_COL32(0, 0, 0, 122), 1.0f);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() +
main_window_text_y_padding_ / 2);
ShowRecentConnections();
ImGui::EndChild();
StatusBar(); StatusBar();
ConnectionStatusWindow(); ConnectionStatusWindow();
return 0; return 0;
} }
int Render::ShowRecentConnections() {
ImGui::Image((ImTextureID)(intptr_t)recent_connection_texture_,
ImVec2((float)recent_connection_image_width_,
(float)recent_connection_image_height_));
return 0;
}

View File

@@ -4,47 +4,44 @@
#include "rd_log.h" #include "rd_log.h"
#include "render.h" #include "render.h"
static int InputTextCallback(ImGuiInputTextCallbackData *data) { static int InputTextCallback(ImGuiInputTextCallbackData *data);
if (data->BufTextLen > 3 && data->Buf[3] != ' ') {
data->InsertChars(3, " ");
}
if (data->BufTextLen > 7 && data->Buf[7] != ' ') {
data->InsertChars(7, " ");
}
return 0;
}
int Render::RemoteWindow() { int Render::RemoteWindow() {
ImGui::SetNextWindowPos(ImVec2(0, title_bar_height_ + local_window_height_), ImGui::SetNextWindowPos(ImVec2(local_window_width_ + 1.0f, title_bar_height_),
ImGuiCond_Always); ImGuiCond_Always);
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f); ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
ImGui::BeginChild("RemoteDesktopWindow", ImGui::BeginChild("RemoteDesktopWindow",
ImVec2(remote_window_width_, remote_window_height_), ImVec2(remote_window_width_, remote_window_height_),
ImGuiChildFlags_Border, ImGuiChildFlags_None,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoBringToFrontOnFocus); ImGuiWindowFlags_NoBringToFrontOnFocus);
ImGui::PopStyleColor(); ImGui::PopStyleColor();
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + main_window_text_y_padding_);
ImGui::Indent(main_child_window_x_padding_ - 1.0f);
ImGui::SetWindowFontScale(1.0f); ImGui::SetWindowFontScale(1.0f);
ImGui::Text(
"%s", localization::remote_desktop[localization_language_index_].c_str()); ImGui::TextColored(
ImVec4(0.0f, 0.0f, 0.0f, 0.5f), "%s",
localization::remote_desktop[localization_language_index_].c_str());
ImGui::Spacing(); ImGui::Spacing();
{ {
ImGui::SetNextWindowPos( ImGui::SetNextWindowPos(
ImVec2(30, title_bar_height_ + local_window_height_ + 50), ImVec2(local_window_width_ + main_child_window_x_padding_ - 1.0f,
title_bar_height_ + main_child_window_y_padding_),
ImGuiCond_Always); ImGuiCond_Always);
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImGui::PushStyleColor(ImGuiCol_ChildBg,
ImVec4(239.0 / 255, 240.0 / 255, 242.0 / 255, 1.0f)); ImVec4(239.0 / 255, 240.0 / 255, 242.0 / 255, 1.0f));
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 10.0f); ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 10.0f);
ImGui::BeginChild( ImGui::BeginChild(
"RemoteDesktopWindow_1", ImVec2(330, 180), ImGuiChildFlags_Border, "RemoteDesktopWindow_1",
ImVec2(remote_child_window_width_, remote_child_window_height_),
ImGuiChildFlags_Border,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoBringToFrontOnFocus); ImGuiWindowFlags_NoBringToFrontOnFocus);
@@ -112,3 +109,15 @@ int Render::RemoteWindow() {
return 0; return 0;
} }
static int InputTextCallback(ImGuiInputTextCallbackData *data) {
if (data->BufTextLen > 3 && data->Buf[3] != ' ') {
data->InsertChars(3, " ");
}
if (data->BufTextLen > 7 && data->Buf[7] != ' ') {
data->InsertChars(7, " ");
}
return 0;
}

View File

@@ -15,15 +15,21 @@
#include "rd_log.h" #include "rd_log.h"
#include "screen_capturer_factory.h" #include "screen_capturer_factory.h"
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "libyuv.h"
#include "stb_image_write.h"
// Refresh Event // Refresh Event
#define REFRESH_EVENT (SDL_USEREVENT + 1) #define REFRESH_EVENT (SDL_USEREVENT + 1)
#define NV12_BUFFER_SIZE 1280 * 720 * 3 / 2 #define NV12_BUFFER_SIZE 1280 * 720 * 3 / 2
#define MOUSE_GRAB_PADDING 5 #define MOUSE_GRAB_PADDING 5
SDL_HitTestResult Render::HitTestCallback(SDL_Window *window, SDL_HitTestResult Render::HitTestCallback(SDL_Window* window,
const SDL_Point *area, void *data) { const SDL_Point* area, void* data) {
Render *render = (Render *)data; Render* render = (Render*)data;
if (!render) { if (!render) {
return SDL_HITTEST_NORMAL; return SDL_HITTEST_NORMAL;
} }
@@ -69,6 +75,60 @@ SDL_HitTestResult Render::HitTestCallback(SDL_Window *window,
return SDL_HITTEST_NORMAL; return SDL_HITTEST_NORMAL;
} }
bool LoadTextureFromMemory(const void* data, size_t data_size,
SDL_Renderer* renderer, SDL_Texture** out_texture,
int* out_width, int* out_height) {
int image_width = 0;
int image_height = 0;
int channels = 4;
unsigned char* image_data =
stbi_load_from_memory((const unsigned char*)data, (int)data_size,
&image_width, &image_height, NULL, 4);
if (image_data == nullptr) {
fprintf(stderr, "Failed to load image: %s\n", stbi_failure_reason());
return false;
}
SDL_Surface* surface = SDL_CreateRGBSurfaceFrom(
(void*)image_data, image_width, image_height, channels * 8,
channels * image_width, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
if (surface == nullptr) {
fprintf(stderr, "Failed to create SDL surface: %s\n", SDL_GetError());
return false;
}
SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface);
if (texture == nullptr)
fprintf(stderr, "Failed to create SDL texture: %s\n", SDL_GetError());
*out_texture = texture;
*out_width = image_width;
*out_height = image_height;
SDL_FreeSurface(surface);
stbi_image_free(image_data);
return true;
}
// Open and read a file, then forward to LoadTextureFromMemory()
bool LoadTextureFromFile(const char* file_name, SDL_Renderer* renderer,
SDL_Texture** out_texture, int* out_width,
int* out_height) {
FILE* f = fopen(file_name, "rb");
if (f == NULL) return false;
fseek(f, 0, SEEK_END);
size_t file_size = (size_t)ftell(f);
if (file_size == -1) return false;
fseek(f, 0, SEEK_SET);
void* file_data = IM_ALLOC(file_size);
fread(file_data, 1, file_size, f);
bool ret = LoadTextureFromMemory(file_data, file_size, renderer, out_texture,
out_width, out_height);
IM_FREE(file_data);
return ret;
}
Render::Render() {} Render::Render() {}
Render::~Render() {} Render::~Render() {}
@@ -162,13 +222,13 @@ int Render::LoadSettingsFromCacheFile() {
} }
int Render::StartScreenCapture() { int Render::StartScreenCapture() {
screen_capturer_ = (ScreenCapturer *)screen_capturer_factory_->Create(); screen_capturer_ = (ScreenCapturer*)screen_capturer_factory_->Create();
last_frame_time_ = std::chrono::duration_cast<std::chrono::milliseconds>( last_frame_time_ = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now().time_since_epoch()) std::chrono::steady_clock::now().time_since_epoch())
.count(); .count();
int screen_capturer_init_ret = screen_capturer_->Init( 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) -> void {
auto now_time = std::chrono::duration_cast<std::chrono::milliseconds>( auto now_time = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now().time_since_epoch()) std::chrono::steady_clock::now().time_since_epoch())
.count(); .count();
@@ -178,7 +238,7 @@ int Render::StartScreenCapture() {
// NV12_BUFFER_SIZE); // NV12_BUFFER_SIZE);
XVideoFrame frame; XVideoFrame frame;
frame.data = (const char *)data; frame.data = (const char*)data;
frame.size = size; frame.size = size;
frame.width = width; frame.width = width;
frame.height = height; frame.height = height;
@@ -213,11 +273,11 @@ int Render::StopScreenCapture() {
int Render::StartSpeakerCapture() { int Render::StartSpeakerCapture() {
if (!speaker_capturer_) { if (!speaker_capturer_) {
speaker_capturer_ = (SpeakerCapturer *)speaker_capturer_factory_->Create(); speaker_capturer_ = (SpeakerCapturer*)speaker_capturer_factory_->Create();
int speaker_capturer_init_ret = speaker_capturer_->Init( int speaker_capturer_init_ret = speaker_capturer_->Init(
[this](unsigned char *data, size_t size) -> void { [this](unsigned char* data, size_t size) -> void {
if (connection_established_) { if (connection_established_) {
SendData(peer_, DATA_TYPE::AUDIO, (const char *)data, size); SendData(peer_, DATA_TYPE::AUDIO, (const char*)data, size);
} }
}); });
@@ -244,7 +304,7 @@ int Render::StopSpeakerCapture() {
int Render::StartMouseControl() { int Render::StartMouseControl() {
device_controller_factory_ = new DeviceControllerFactory(); device_controller_factory_ = new DeviceControllerFactory();
mouse_controller_ = (MouseController *)device_controller_factory_->Create( mouse_controller_ = (MouseController*)device_controller_factory_->Create(
DeviceControllerFactory::Device::Mouse); DeviceControllerFactory::Device::Mouse);
int mouse_controller_init_ret = int mouse_controller_init_ret =
mouse_controller_->Init(screen_width_, screen_height_); mouse_controller_->Init(screen_width_, screen_height_);
@@ -488,7 +548,7 @@ int Render::DestroyStreamWindow() {
int Render::SetupFontAndStyle() { int Render::SetupFontAndStyle() {
// Setup Dear ImGui style // Setup Dear ImGui style
ImGuiIO &io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
// Master keyboard navigation enable flag. Enable full Tabbing + directional // Master keyboard navigation enable flag. Enable full Tabbing + directional
// arrows + space/enter to activate. // arrows + space/enter to activate.
io.ConfigFlags |= io.ConfigFlags |=
@@ -678,6 +738,8 @@ int Render::DrawStreamWindow() {
return 0; return 0;
} }
int Render::LoadRecentConnections() { return 0; }
int Render::Run() { int Render::Run() {
LoadSettingsFromCacheFile(); LoadSettingsFromCacheFile();
@@ -763,6 +825,44 @@ int Render::Run() {
localization_language_index_last_ = localization_language_index_; localization_language_index_last_ = localization_language_index_;
} }
{
const int scaled_video_width_ = 128;
const int scaled_video_height_ = 72;
// uint8_t scaled_yuv_data =
// new uint8_t[scaled_video_width_ * scaled_video_height_ * 3 / 2];
// uint8_t* rgb_data =
// new uint8_t[scaled_video_width_ * scaled_video_height_ * 3];
uint8_t
scaled_yuv_data[scaled_video_width_ * scaled_video_height_ * 3 / 2];
uint8_t rgb_data[scaled_video_width_ * scaled_video_height_ * 3];
libyuv::I420Scale(
dst_buffer_, video_width_, dst_buffer_ + video_width_ * video_height_,
video_width_ / 2, dst_buffer_ + video_width_ * video_height_ * 5 / 4,
video_width_ / 2, video_width_, video_height_, scaled_yuv_data,
scaled_video_width_,
scaled_yuv_data + scaled_video_width_ * scaled_video_height_,
scaled_video_width_ / 2,
scaled_yuv_data + scaled_video_width_ * scaled_video_height_ * 5 / 4,
scaled_video_width_ / 2, scaled_video_width_, scaled_video_width_,
libyuv::FilterMode::kFilterNone);
libyuv::I420ToRGB24(
scaled_yuv_data, scaled_video_width_,
scaled_yuv_data + scaled_video_width_ * scaled_video_height_,
scaled_video_width_ / 2,
scaled_yuv_data + scaled_video_width_ * scaled_video_height_ * 5 / 4,
scaled_video_width_ / 2, rgb_data, scaled_video_width_ * 3,
scaled_video_width_, scaled_video_height_);
stbi_write_png("RecentConnectionImage01.png", scaled_video_width_,
scaled_video_height_, 3, rgb_data,
scaled_video_width_ * 3);
// delete[] scaled_yuv_data;
// delete[] rgb_data;
}
SDL_Event event; SDL_Event event;
while (SDL_PollEvent(&event)) { while (SDL_PollEvent(&event)) {
{ {
@@ -804,11 +904,51 @@ int Render::Run() {
is_client_mode_ = false; is_client_mode_ = false;
audio_capture_button_pressed_ = false; audio_capture_button_pressed_ = false;
fullscreen_button_pressed_ = false; fullscreen_button_pressed_ = false;
reload_recent_connections_ = true;
SDL_SetWindowFullscreen(main_window_, SDL_FALSE); SDL_SetWindowFullscreen(main_window_, SDL_FALSE);
memset(audio_buffer_, 0, 960); memset(audio_buffer_, 0, 720);
SDL_SetWindowSize(main_window_, main_window_width_default_, SDL_SetWindowSize(main_window_, main_window_width_default_,
main_window_height_default_); main_window_height_default_);
// {
// int scaled_video_width_ = 128;
// int scaled_video_height_ = 72;
// uint8_t* scaled_yuv_data =
// new uint8_t[scaled_video_width_ * scaled_video_height_ * 3 /
// 2];
// uint8_t* rgb_data =
// new uint8_t[scaled_video_width_ * scaled_video_height_ * 3];
// libyuv::I420Scale(
// dst_buffer_, video_width_,
// dst_buffer_ + video_width_ * video_height_, video_width_ / 2,
// dst_buffer_ + video_width_ * video_height_ * 5 / 4,
// video_width_ / 2, video_width_, video_height_,
// scaled_yuv_data, scaled_video_width_, scaled_yuv_data +
// scaled_video_width_ * scaled_video_height_,
// scaled_video_width_ / 2,
// scaled_yuv_data +
// scaled_video_width_ * scaled_video_height_ * 5 / 4,
// scaled_video_width_ / 2, scaled_video_width_,
// scaled_video_width_, libyuv::FilterMode::kFilterNone);
// libyuv::I420ToRGB24(
// scaled_yuv_data, scaled_video_width_,
// scaled_yuv_data + scaled_video_width_ * scaled_video_height_,
// scaled_video_width_ / 2,
// scaled_yuv_data +
// scaled_video_width_ * scaled_video_height_ * 5 / 4,
// scaled_video_width_ / 2, rgb_data, scaled_video_width_ * 3,
// scaled_video_width_, scaled_video_height_);
// stbi_write_png("RecentConnectionImage01.jpg",
// scaled_video_width_,
// scaled_video_height_, 3, rgb_data,
// scaled_video_width_ * 3);
// delete[] scaled_yuv_data;
// delete[] rgb_data;
// }
// SDL_Rect display_bounds; // SDL_Rect display_bounds;
// SDL_GetDisplayBounds(0, &display_bounds); // SDL_GetDisplayBounds(0, &display_bounds);
// int center_x = (display_bounds.w - main_window_width_default_) / 2; // int center_x = (display_bounds.w - main_window_width_default_) / 2;
@@ -886,6 +1026,17 @@ int Render::Run() {
} }
} }
if (reload_recent_connections_) {
bool ret = LoadTextureFromFile(
"RecentConnectionImage01.png", main_renderer_,
&recent_connection_texture_, &recent_connection_image_width_,
&recent_connection_image_height_);
if (!ret) {
LOG_ERROR("Load recent connections image failed");
}
reload_recent_connections_ = false;
}
if (connection_established_ && streaming_) { if (connection_established_ && streaming_) {
CreateStreamWindow(); CreateStreamWindow();
SetupStreamWindow(); SetupStreamWindow();

View File

@@ -42,6 +42,8 @@ class Render {
int AboutWindow(); int AboutWindow();
int StatusBar(); int StatusBar();
int ConnectionStatusWindow(); int ConnectionStatusWindow();
int LoadRecentConnections();
int ShowRecentConnections();
private: private:
int CreateRtcConnection(); int CreateRtcConnection();
@@ -150,32 +152,39 @@ class Render {
char client_password_[20] = ""; char client_password_[20] = "";
private: private:
int title_bar_width_ = 960; int title_bar_width_ = 640;
int title_bar_height_ = 30; int title_bar_height_ = 30;
int screen_width_ = 1280; int screen_width_ = 1280;
int screen_height_ = 720; int screen_height_ = 720;
int main_window_width_default_ = 960; int main_window_width_default_ = 640;
int main_window_height_default_ = 590; int main_window_height_default_ = 480;
int main_window_width_ = 960; int main_window_width_ = 640;
int main_window_height_ = 590; int main_window_height_ = 480;
int main_window_width_last_ = 960; int main_window_width_last_ = 640;
int main_window_height_last_ = 540; int main_window_height_last_ = 480;
int stream_window_width_default_ = 1280; int stream_window_width_default_ = 1280;
int stream_window_height_default_ = 720; int stream_window_height_default_ = 720;
int stream_window_width_ = 1280; int stream_window_width_ = 1280;
int stream_window_height_ = 720; int stream_window_height_ = 720;
int stream_window_width_last_ = 1280; int stream_window_width_last_ = 1280;
int stream_window_height_last_ = 720; int stream_window_height_last_ = 720;
int main_window_width_before_maximized_ = 960; int main_window_width_before_maximized_ = 640;
int main_window_height_before_maximized_ = 590; int main_window_height_before_maximized_ = 480;
int control_window_min_width_ = 20; int control_window_min_width_ = 20;
int control_window_max_width_ = 170; int control_window_max_width_ = 170;
int control_window_width_ = 170; int control_window_width_ = 170;
int control_window_height_ = 40; int control_window_height_ = 40;
int local_window_width_ = 720; int local_window_width_ = 320;
int local_window_height_ = 270; int local_window_height_ = 260;
int remote_window_width_ = 720; int remote_window_width_ = 320;
int remote_window_height_ = 270; int remote_window_height_ = 260;
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_ = 20;
int main_child_window_x_padding_ = 27;
int main_child_window_y_padding_ = 60;
int status_bar_height_ = 20; int status_bar_height_ = 20;
int connection_status_window_width_ = 200; int connection_status_window_width_ = 200;
int connection_status_window_height_ = 150; int connection_status_window_height_ = 150;
@@ -187,7 +196,7 @@ class Render {
int control_bar_pos_x_ = 0; int control_bar_pos_x_ = 0;
int control_bar_pos_y_ = 30; int control_bar_pos_y_ = 30;
int main_window_width_real_ = 960; int main_window_width_real_ = 720;
int main_window_height_real_ = 540; int main_window_height_real_ = 540;
float main_window_dpi_scaling_w_ = 1.0f; float main_window_dpi_scaling_w_ = 1.0f;
float main_window_dpi_scaling_h_ = 1.0f; float main_window_dpi_scaling_h_ = 1.0f;
@@ -214,6 +223,11 @@ class Render {
bool stream_window_created_ = false; bool stream_window_created_ = false;
bool stream_window_inited_ = false; bool stream_window_inited_ = false;
// recent connections
SDL_Texture *recent_connection_texture_ = nullptr;
int recent_connection_image_width_ = 128;
int recent_connection_image_height_ = 72;
// video window // video window
SDL_Texture *stream_texture_ = nullptr; SDL_Texture *stream_texture_ = nullptr;
SDL_Rect stream_render_rect_; SDL_Rect stream_render_rect_;
@@ -253,6 +267,7 @@ class Render {
bool is_client_mode_ = false; bool is_client_mode_ = false;
bool is_control_bar_in_left_ = true; bool is_control_bar_in_left_ = true;
bool control_window_width_is_changing_ = false; bool control_window_width_is_changing_ = false;
bool reload_recent_connections_ = true;
double copy_start_time_ = 0; double copy_start_time_ = 0;
double regenerate_password_start_time_ = 0; double regenerate_password_start_time_ = 0;
@@ -282,7 +297,7 @@ class Render {
private: private:
SDL_AudioDeviceID input_dev_; SDL_AudioDeviceID input_dev_;
SDL_AudioDeviceID output_dev_; SDL_AudioDeviceID output_dev_;
unsigned char audio_buffer_[960]; unsigned char audio_buffer_[720];
int audio_len_ = 0; int audio_len_ = 0;
unsigned char *dst_buffer_ = nullptr; unsigned char *dst_buffer_ = nullptr;
int dst_buffer_capacity_ = 0; int dst_buffer_capacity_ = 0;
@@ -298,6 +313,7 @@ class Render {
private: private:
char client_id_[10] = ""; char client_id_[10] = "";
char client_id_display_[12] = "";
char password_saved_[7] = ""; char password_saved_[7] = "";
int language_button_value_ = 0; int language_button_value_ = 0;
int video_quality_button_value_ = 0; int video_quality_button_value_ = 0;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -124,6 +124,7 @@ target("localization")
target("single_window") target("single_window")
set_kind("object") set_kind("object")
add_packages("libyuv")
add_deps("rd_log", "common", "localization", "config_center", "projectx", "screen_capturer", "speaker_capturer", "device_controller") add_deps("rd_log", "common", "localization", "config_center", "projectx", "screen_capturer", "speaker_capturer", "device_controller")
if is_os("macosx") then if is_os("macosx") then
add_packages("ffmpeg") add_packages("ffmpeg")