[feat] add support for self-hosted server configuration

This commit is contained in:
dijunkun
2025-10-18 23:41:10 +08:00
parent adfe14809f
commit 5590aaeb1e
32 changed files with 4030 additions and 242 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,64 +1,229 @@
#include "config_center.h" #include "config_center.h"
#include "rd_log.h" ConfigCenter::ConfigCenter(const std::string& config_path,
const std::string& cert_file_path)
ConfigCenter::ConfigCenter() {} : config_path_(config_path),
cert_file_path_(cert_file_path),
cert_file_path_default_(cert_file_path) {
ini_.SetUnicode(true);
Load();
}
ConfigCenter::~ConfigCenter() {} ConfigCenter::~ConfigCenter() {}
int ConfigCenter::Load() {
SI_Error rc = ini_.LoadFile(config_path_.c_str());
if (rc < 0) {
Save();
return -1;
}
language_ = static_cast<LANGUAGE>(
ini_.GetLongValue(section_, "language", static_cast<long>(language_)));
video_quality_ = static_cast<VIDEO_QUALITY>(ini_.GetLongValue(
section_, "video_quality", static_cast<long>(video_quality_)));
video_frame_rate_ = static_cast<VIDEO_FRAME_RATE>(ini_.GetLongValue(
section_, "video_frame_rate", static_cast<long>(video_frame_rate_)));
video_encode_format_ = static_cast<VIDEO_ENCODE_FORMAT>(
ini_.GetLongValue(section_, "video_encode_format",
static_cast<long>(video_encode_format_)));
hardware_video_codec_ = ini_.GetBoolValue(section_, "hardware_video_codec",
hardware_video_codec_);
enable_turn_ = ini_.GetBoolValue(section_, "enable_turn", enable_turn_);
enable_srtp_ = ini_.GetBoolValue(section_, "enable_srtp", enable_srtp_);
server_host_ = ini_.GetValue(section_, "server_host", server_host_.c_str());
server_port_ = static_cast<int>(
ini_.GetLongValue(section_, "server_port", server_port_));
cert_file_path_ =
ini_.GetValue(section_, "cert_file_path", cert_file_path_.c_str());
enable_self_hosted_ =
ini_.GetBoolValue(section_, "enable_self_hosted", enable_self_hosted_);
return 0;
}
int ConfigCenter::Save() {
ini_.SetLongValue(section_, "language", static_cast<long>(language_));
ini_.SetLongValue(section_, "video_quality",
static_cast<long>(video_quality_));
ini_.SetLongValue(section_, "video_frame_rate",
static_cast<long>(video_frame_rate_));
ini_.SetLongValue(section_, "video_encode_format",
static_cast<long>(video_encode_format_));
ini_.SetBoolValue(section_, "hardware_video_codec", hardware_video_codec_);
ini_.SetBoolValue(section_, "enable_turn", enable_turn_);
ini_.SetBoolValue(section_, "enable_srtp", enable_srtp_);
ini_.SetValue(section_, "server_host", server_host_.c_str());
ini_.SetLongValue(section_, "server_port", static_cast<long>(server_port_));
ini_.SetValue(section_, "cert_file_path", cert_file_path_.c_str());
ini_.SetBoolValue(section_, "enable_self_hosted", enable_self_hosted_);
SI_Error rc = ini_.SaveFile(config_path_.c_str());
if (rc < 0) {
return -1;
}
return 0;
}
// setters
int ConfigCenter::SetLanguage(LANGUAGE language) { int ConfigCenter::SetLanguage(LANGUAGE language) {
language_ = language; language_ = language;
ini_.SetLongValue(section_, "language", static_cast<long>(language_));
SI_Error rc = ini_.SaveFile(config_path_.c_str());
if (rc < 0) {
return -1;
}
return 0; return 0;
} }
int ConfigCenter::SetVideoQuality(VIDEO_QUALITY video_quality) { int ConfigCenter::SetVideoQuality(VIDEO_QUALITY video_quality) {
video_quality_ = video_quality; video_quality_ = video_quality;
ini_.SetLongValue(section_, "video_quality",
static_cast<long>(video_quality_));
SI_Error rc = ini_.SaveFile(config_path_.c_str());
if (rc < 0) {
return -1;
}
return 0; return 0;
} }
int ConfigCenter::SetVideoFrameRate(VIDEO_FRAME_RATE video_frame_rate) { int ConfigCenter::SetVideoFrameRate(VIDEO_FRAME_RATE video_frame_rate) {
video_frame_rate_ = video_frame_rate; video_frame_rate_ = video_frame_rate;
ini_.SetLongValue(section_, "video_frame_rate",
static_cast<long>(video_frame_rate_));
SI_Error rc = ini_.SaveFile(config_path_.c_str());
if (rc < 0) {
return -1;
}
return 0; return 0;
} }
int ConfigCenter::SetVideoEncodeFormat( int ConfigCenter::SetVideoEncodeFormat(
VIDEO_ENCODE_FORMAT video_encode_format) { VIDEO_ENCODE_FORMAT video_encode_format) {
video_encode_format_ = video_encode_format; video_encode_format_ = video_encode_format;
ini_.SetLongValue(section_, "video_encode_format",
static_cast<long>(video_encode_format_));
SI_Error rc = ini_.SaveFile(config_path_.c_str());
if (rc < 0) {
return -1;
}
return 0; return 0;
} }
int ConfigCenter::SetHardwareVideoCodec(bool hardware_video_codec) { int ConfigCenter::SetHardwareVideoCodec(bool hardware_video_codec) {
hardware_video_codec_ = hardware_video_codec; hardware_video_codec_ = hardware_video_codec;
ini_.SetBoolValue(section_, "hardware_video_codec", hardware_video_codec_);
SI_Error rc = ini_.SaveFile(config_path_.c_str());
if (rc < 0) {
return -1;
}
return 0; return 0;
} }
int ConfigCenter::SetTurn(bool enable_turn) { int ConfigCenter::SetTurn(bool enable_turn) {
enable_turn_ = enable_turn; enable_turn_ = enable_turn;
ini_.SetBoolValue(section_, "enable_turn", enable_turn_);
SI_Error rc = ini_.SaveFile(config_path_.c_str());
if (rc < 0) {
return -1;
}
return 0; return 0;
} }
int ConfigCenter::SetSrtp(bool enable_srtp) { int ConfigCenter::SetSrtp(bool enable_srtp) {
enable_srtp_ = enable_srtp; enable_srtp_ = enable_srtp;
ini_.SetBoolValue(section_, "enable_srtp", enable_srtp_);
SI_Error rc = ini_.SaveFile(config_path_.c_str());
if (rc < 0) {
return -1;
}
return 0; return 0;
} }
ConfigCenter::LANGUAGE ConfigCenter::GetLanguage() { return language_; } int ConfigCenter::SetServerHost(const std::string& server_host) {
server_host_ = server_host;
ini_.SetValue(section_, "server_host", server_host_.c_str());
SI_Error rc = ini_.SaveFile(config_path_.c_str());
if (rc < 0) {
return -1;
}
return 0;
}
ConfigCenter::VIDEO_QUALITY ConfigCenter::GetVideoQuality() { int ConfigCenter::SetServerPort(int server_port) {
server_port_ = server_port;
ini_.SetLongValue(section_, "server_port", static_cast<long>(server_port_));
SI_Error rc = ini_.SaveFile(config_path_.c_str());
if (rc < 0) {
return -1;
}
return 0;
}
int ConfigCenter::SetCertFilePath(const std::string& cert_file_path) {
cert_file_path_ = cert_file_path;
ini_.SetValue(section_, "cert_file_path", cert_file_path_.c_str());
SI_Error rc = ini_.SaveFile(config_path_.c_str());
if (rc < 0) {
return -1;
}
return 0;
}
int ConfigCenter::SetSelfHosted(bool enable_self_hosted) {
enable_self_hosted_ = enable_self_hosted;
SI_Error rc = ini_.SaveFile(config_path_.c_str());
if (rc < 0) {
return -1;
}
return 0;
}
// getters
ConfigCenter::LANGUAGE ConfigCenter::GetLanguage() const { return language_; }
ConfigCenter::VIDEO_QUALITY ConfigCenter::GetVideoQuality() const {
return video_quality_; return video_quality_;
} }
int ConfigCenter::GetVideoFrameRate() { ConfigCenter::VIDEO_FRAME_RATE ConfigCenter::GetVideoFrameRate() const {
int fps = video_frame_rate_ == VIDEO_FRAME_RATE::FPS_30 ? 30 : 60; return video_frame_rate_;
return fps;
} }
ConfigCenter::VIDEO_ENCODE_FORMAT ConfigCenter::GetVideoEncodeFormat() { ConfigCenter::VIDEO_ENCODE_FORMAT ConfigCenter::GetVideoEncodeFormat() const {
return video_encode_format_; return video_encode_format_;
} }
bool ConfigCenter::IsHardwareVideoCodec() { return hardware_video_codec_; } bool ConfigCenter::IsHardwareVideoCodec() const {
return hardware_video_codec_;
}
bool ConfigCenter::IsEnableTurn() { return enable_turn_; } bool ConfigCenter::IsEnableTurn() const { return enable_turn_; }
bool ConfigCenter::IsEnableSrtp() { return enable_srtp_; } bool ConfigCenter::IsEnableSrtp() const { return enable_srtp_; }
std::string ConfigCenter::GetServerHost() const { return server_host_; }
int ConfigCenter::GetServerPort() const { return server_port_; }
std::string ConfigCenter::GetCertFilePath() const { return cert_file_path_; }
std::string ConfigCenter::GetDefaultServerHost() const {
return server_host_default_;
}
int ConfigCenter::GetDefaultServerPort() const { return server_port_default_; }
std::string ConfigCenter::GetDefaultCertFilePath() const {
return cert_file_path_default_;
}
bool ConfigCenter::IsSelfHosted() const { return enable_self_hosted_; }

View File

@@ -7,18 +7,24 @@
#ifndef _CONFIG_CENTER_H_ #ifndef _CONFIG_CENTER_H_
#define _CONFIG_CENTER_H_ #define _CONFIG_CENTER_H_
#include <string>
#include "SimpleIni.h"
class ConfigCenter { class ConfigCenter {
public: public:
enum class LANGUAGE { CHINESE = 0, ENGLISH = 1 }; enum class LANGUAGE { CHINESE = 0, ENGLISH = 1 };
enum class VIDEO_QUALITY { LOW = 0, MEDIUM = 1, HIGH = 2 }; enum class VIDEO_QUALITY { LOW = 0, MEDIUM = 1, HIGH = 2 };
enum class VIDEO_FRAME_RATE { FPS_30 = 0, FPS_60 = 1 }; enum class VIDEO_FRAME_RATE { FPS_30 = 0, FPS_60 = 1 };
enum class VIDEO_ENCODE_FORMAT { AV1 = 0, H264 = 1 }; enum class VIDEO_ENCODE_FORMAT { H264 = 0, AV1 = 1 };
public: public:
ConfigCenter(); explicit ConfigCenter(
const std::string& config_path = "config.ini",
const std::string& cert_file_path = "crossdesk.cn_root.crt");
~ConfigCenter(); ~ConfigCenter();
public: // write config
int SetLanguage(LANGUAGE language); int SetLanguage(LANGUAGE language);
int SetVideoQuality(VIDEO_QUALITY video_quality); int SetVideoQuality(VIDEO_QUALITY video_quality);
int SetVideoFrameRate(VIDEO_FRAME_RATE video_frame_rate); int SetVideoFrameRate(VIDEO_FRAME_RATE video_frame_rate);
@@ -26,25 +32,50 @@ class ConfigCenter {
int SetHardwareVideoCodec(bool hardware_video_codec); int SetHardwareVideoCodec(bool hardware_video_codec);
int SetTurn(bool enable_turn); int SetTurn(bool enable_turn);
int SetSrtp(bool enable_srtp); int SetSrtp(bool enable_srtp);
int SetServerHost(const std::string& server_host);
int SetServerPort(int server_port);
int SetCertFilePath(const std::string& cert_file_path);
int SetSelfHosted(bool enable_self_hosted);
public: // read config
LANGUAGE GetLanguage();
VIDEO_QUALITY GetVideoQuality(); LANGUAGE GetLanguage() const;
int GetVideoFrameRate(); VIDEO_QUALITY GetVideoQuality() const;
VIDEO_ENCODE_FORMAT GetVideoEncodeFormat(); VIDEO_FRAME_RATE GetVideoFrameRate() const;
bool IsHardwareVideoCodec(); VIDEO_ENCODE_FORMAT GetVideoEncodeFormat() const;
bool IsEnableTurn(); bool IsHardwareVideoCodec() const;
bool IsEnableSrtp(); bool IsEnableTurn() const;
bool IsEnableSrtp() const;
std::string GetServerHost() const;
int GetServerPort() const;
std::string GetCertFilePath() const;
std::string GetDefaultServerHost() const;
int GetDefaultServerPort() const;
std::string GetDefaultCertFilePath() const;
bool IsSelfHosted() const;
int Load();
int Save();
private: private:
// Default value should be same with parameters in localization.h std::string config_path_;
std::string cert_file_path_;
CSimpleIniA ini_;
const char* section_ = "Settings";
LANGUAGE language_ = LANGUAGE::CHINESE; LANGUAGE language_ = LANGUAGE::CHINESE;
VIDEO_QUALITY video_quality_ = VIDEO_QUALITY::MEDIUM; VIDEO_QUALITY video_quality_ = VIDEO_QUALITY::MEDIUM;
VIDEO_FRAME_RATE video_frame_rate_ = VIDEO_FRAME_RATE::FPS_30; VIDEO_FRAME_RATE video_frame_rate_ = VIDEO_FRAME_RATE::FPS_30;
VIDEO_ENCODE_FORMAT video_encode_format_ = VIDEO_ENCODE_FORMAT::AV1; VIDEO_ENCODE_FORMAT video_encode_format_ = VIDEO_ENCODE_FORMAT::H264;
bool hardware_video_codec_ = false; bool hardware_video_codec_ = false;
bool enable_turn_ = false; bool enable_turn_ = false;
bool enable_srtp_ = false; bool enable_srtp_ = false;
std::string server_host_ = "api.crossdesk.cn";
int server_port_ = 9099;
std::string server_host_default_ = "api.crossdesk.cn";
int server_port_default_ = 9099;
std::string cert_file_path_default_ = "";
bool enable_self_hosted_ = false;
}; };
#endif #endif

View File

@@ -1,6 +1,6 @@
#include <random> #include <random>
#include "layout_style.h" #include "layout.h"
#include "localization.h" #include "localization.h"
#include "rd_log.h" #include "rd_log.h"
#include "render.h" #include "render.h"

View File

@@ -1,4 +1,4 @@
#include "layout_style.h" #include "layout.h"
#include "localization.h" #include "localization.h"
#include "rd_log.h" #include "rd_log.h"
#include "render.h" #include "render.h"

View File

@@ -11,7 +11,7 @@
#include "device_controller_factory.h" #include "device_controller_factory.h"
#include "fa_regular_400.h" #include "fa_regular_400.h"
#include "fa_solid_900.h" #include "fa_solid_900.h"
#include "layout_style.h" #include "layout.h"
#include "localization.h" #include "localization.h"
#include "platform.h" #include "platform.h"
#include "rd_log.h" #include "rd_log.h"
@@ -171,7 +171,8 @@ Render::~Render() {}
int Render::SaveSettingsIntoCacheFile() { int Render::SaveSettingsIntoCacheFile() {
cd_cache_mutex_.lock(); cd_cache_mutex_.lock();
std::ofstream cd_cache_file(cache_path_ + "/cache.cd", std::ios::binary); std::ofstream cd_cache_file(cache_path_ + "/secure_cache.enc",
std::ios::binary);
if (!cd_cache_file) { if (!cd_cache_file) {
cd_cache_mutex_.unlock(); cd_cache_mutex_.unlock();
return -1; return -1;
@@ -181,18 +182,6 @@ int Render::SaveSettingsIntoCacheFile() {
sizeof(cd_cache_.client_id_with_password)); sizeof(cd_cache_.client_id_with_password));
memcpy(cd_cache_.client_id_with_password, client_id_with_password_, memcpy(cd_cache_.client_id_with_password, client_id_with_password_,
sizeof(client_id_with_password_)); sizeof(client_id_with_password_));
memcpy(&cd_cache_.language, &language_button_value_,
sizeof(language_button_value_));
memcpy(&cd_cache_.video_quality, &video_quality_button_value_,
sizeof(video_quality_button_value_));
memcpy(&cd_cache_.video_frame_rate, &video_frame_rate_button_value_,
sizeof(video_frame_rate_button_value_));
memcpy(&cd_cache_.video_encode_format, &video_encode_format_button_value_,
sizeof(video_encode_format_button_value_));
memcpy(&cd_cache_.enable_hardware_video_codec, &enable_hardware_video_codec_,
sizeof(enable_hardware_video_codec_));
memcpy(&cd_cache_.enable_turn, &enable_turn_, sizeof(enable_turn_));
memcpy(&cd_cache_.enable_srtp, &enable_srtp_, sizeof(enable_srtp_));
memcpy(&cd_cache_.key, &aes128_key_, sizeof(aes128_key_)); memcpy(&cd_cache_.key, &aes128_key_, sizeof(aes128_key_));
memcpy(&cd_cache_.iv, &aes128_iv_, sizeof(aes128_iv_)); memcpy(&cd_cache_.iv, &aes128_iv_, sizeof(aes128_iv_));
@@ -200,49 +189,19 @@ int Render::SaveSettingsIntoCacheFile() {
cd_cache_file.close(); cd_cache_file.close();
cd_cache_mutex_.unlock(); cd_cache_mutex_.unlock();
config_center_.SetLanguage((ConfigCenter::LANGUAGE)language_button_value_);
config_center_.SetVideoQuality(
(ConfigCenter::VIDEO_QUALITY)video_quality_button_value_);
config_center_.SetVideoFrameRate(
(ConfigCenter::VIDEO_FRAME_RATE)video_frame_rate_button_value_);
config_center_.SetVideoEncodeFormat(
(ConfigCenter::VIDEO_ENCODE_FORMAT)video_encode_format_button_value_);
config_center_.SetHardwareVideoCodec(enable_hardware_video_codec_);
config_center_.SetTurn(enable_turn_);
config_center_.SetSrtp(enable_srtp_);
LOG_INFO("Save settings into cache file success");
return 0; return 0;
} }
int Render::LoadSettingsFromCacheFile() { int Render::LoadSettingsFromCacheFile() {
cd_cache_mutex_.lock(); cd_cache_mutex_.lock();
std::ifstream cd_cache_file(cache_path_ + "/cache.cd", std::ios::binary); std::ifstream cd_cache_file(cache_path_ + "/secure_cache.enc",
std::ios::binary);
if (!cd_cache_file) { if (!cd_cache_file) {
cd_cache_mutex_.unlock(); cd_cache_mutex_.unlock();
LOG_INFO("Init cache file by using default settings");
memset(password_saved_, 0, sizeof(password_saved_)); memset(password_saved_, 0, sizeof(password_saved_));
memset(aes128_key_, 0, sizeof(aes128_key_)); memset(aes128_key_, 0, sizeof(aes128_key_));
memset(aes128_iv_, 0, sizeof(aes128_iv_)); memset(aes128_iv_, 0, sizeof(aes128_iv_));
language_button_value_ = 0;
video_quality_button_value_ = 0;
video_encode_format_button_value_ = 1;
enable_hardware_video_codec_ = false;
enable_turn_ = false;
enable_srtp_ = false;
config_center_.SetLanguage((ConfigCenter::LANGUAGE)language_button_value_);
config_center_.SetVideoQuality(
(ConfigCenter::VIDEO_QUALITY)video_quality_button_value_);
config_center_.SetVideoFrameRate(
(ConfigCenter::VIDEO_FRAME_RATE)video_frame_rate_button_value_);
config_center_.SetVideoEncodeFormat(
(ConfigCenter::VIDEO_ENCODE_FORMAT)video_encode_format_button_value_);
config_center_.SetHardwareVideoCodec(enable_hardware_video_codec_);
config_center_.SetTurn(enable_turn_);
config_center_.SetSrtp(enable_srtp_);
thumbnail_.reset(); thumbnail_.reset();
thumbnail_ = std::make_unique<Thumbnail>(cache_path_ + "/thumbnails/"); thumbnail_ = std::make_unique<Thumbnail>(cache_path_ + "/thumbnails/");
@@ -289,13 +248,14 @@ int Render::LoadSettingsFromCacheFile() {
thumbnail_ = std::make_unique<Thumbnail>(cache_path_ + "/thumbnails/", thumbnail_ = std::make_unique<Thumbnail>(cache_path_ + "/thumbnails/",
aes128_key_, aes128_iv_); aes128_key_, aes128_iv_);
language_button_value_ = cd_cache_.language; language_button_value_ = (int)config_center_->GetLanguage();
video_quality_button_value_ = cd_cache_.video_quality; video_quality_button_value_ = (int)config_center_->GetVideoQuality();
video_frame_rate_button_value_ = cd_cache_.video_frame_rate; video_frame_rate_button_value_ = (int)config_center_->GetVideoFrameRate();
video_encode_format_button_value_ = cd_cache_.video_encode_format; video_encode_format_button_value_ =
enable_hardware_video_codec_ = cd_cache_.enable_hardware_video_codec; (int)config_center_->GetVideoEncodeFormat();
enable_turn_ = cd_cache_.enable_turn; enable_hardware_video_codec_ = config_center_->IsHardwareVideoCodec();
enable_srtp_ = cd_cache_.enable_srtp; enable_turn_ = config_center_->IsEnableTurn();
enable_srtp_ = config_center_->IsEnableSrtp();
language_button_value_last_ = language_button_value_; language_button_value_last_ = language_button_value_;
video_quality_button_value_last_ = video_quality_button_value_; video_quality_button_value_last_ = video_quality_button_value_;
@@ -304,17 +264,6 @@ int Render::LoadSettingsFromCacheFile() {
enable_turn_last_ = enable_turn_; enable_turn_last_ = enable_turn_;
enable_srtp_last_ = enable_srtp_; enable_srtp_last_ = enable_srtp_;
config_center_.SetLanguage((ConfigCenter::LANGUAGE)language_button_value_);
config_center_.SetVideoQuality(
(ConfigCenter::VIDEO_QUALITY)video_quality_button_value_);
config_center_.SetVideoFrameRate(
(ConfigCenter::VIDEO_FRAME_RATE)video_frame_rate_button_value_);
config_center_.SetVideoEncodeFormat(
(ConfigCenter::VIDEO_ENCODE_FORMAT)video_encode_format_button_value_);
config_center_.SetHardwareVideoCodec(enable_hardware_video_codec_);
config_center_.SetTurn(enable_turn_);
config_center_.SetSrtp(enable_srtp_);
LOG_INFO("Load settings from cache file"); LOG_INFO("Load settings from cache file");
return 0; return 0;
@@ -328,18 +277,21 @@ int Render::ScreenCapturerInit() {
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 fps = config_center_.GetVideoFrameRate(); int fps = config_center_->GetVideoFrameRate() ==
ConfigCenter::VIDEO_FRAME_RATE::FPS_30
? 30
: 60;
LOG_INFO("Init screen capturer with {} fps", fps); LOG_INFO("Init screen capturer with {} fps", fps);
int screen_capturer_init_ret = screen_capturer_->Init( int screen_capturer_init_ret = screen_capturer_->Init(
fps, fps,
[this](unsigned char* data, int size, int width, int height, [this, fps](unsigned char* data, int size, int width, int height,
const char* display_name) -> void { const char* display_name) -> 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();
auto duration = now_time - last_frame_time_; auto duration = now_time - last_frame_time_;
if (duration * config_center_.GetVideoFrameRate() >= 1000) { // ~60 FPS if (duration * fps >= 1000) { // ~60 FPS
XVideoFrame frame; XVideoFrame frame;
frame.data = (const char*)data; frame.data = (const char*)data;
frame.size = size; frame.size = size;
@@ -474,25 +426,53 @@ int Render::StopKeyboardCapturer() {
int Render::CreateConnectionPeer() { int Render::CreateConnectionPeer() {
params_.use_cfg_file = false; params_.use_cfg_file = false;
params_.signal_server_ip = "api.crossdesk.cn";
params_.signal_server_port = 9099; std::string server_ip;
params_.stun_server_ip = "150.158.81.30"; int server_port;
std::string server_cert_path;
if (config_center_->IsSelfHosted()) {
server_ip = config_center_->GetServerHost();
server_port = config_center_->GetServerPort();
server_cert_path = config_center_->GetCertFilePath();
} else {
server_ip = config_center_->GetDefaultServerHost();
server_port = config_center_->GetDefaultServerPort();
server_cert_path = config_center_->GetDefaultCertFilePath();
}
strncpy((char*)params_.signal_server_ip, server_ip.c_str(),
sizeof(params_.signal_server_ip) - 1);
params_.signal_server_ip[sizeof(params_.signal_server_ip) - 1] = '\0';
params_.signal_server_port = server_port;
strncpy((char*)params_.stun_server_ip, server_ip.c_str(),
sizeof(params_.stun_server_ip) - 1);
params_.stun_server_ip[sizeof(params_.stun_server_ip) - 1] = '\0';
params_.stun_server_port = 3478; params_.stun_server_port = 3478;
params_.turn_server_ip = "150.158.81.30"; strncpy((char*)params_.turn_server_ip, server_ip.c_str(),
sizeof(params_.turn_server_ip) - 1);
params_.turn_server_ip[sizeof(params_.turn_server_ip) - 1] = '\0';
params_.turn_server_port = 3478; params_.turn_server_port = 3478;
params_.turn_server_username = "dijunkun"; strncpy((char*)params_.turn_server_username, "dijunkun",
params_.turn_server_password = "dijunkunpw"; sizeof(params_.turn_server_username) - 1);
params_.tls_cert_path = std::filesystem::exists(cert_path_) params_.turn_server_username[sizeof(params_.turn_server_username) - 1] = '\0';
? cert_path_.c_str() strncpy((char*)params_.turn_server_password, "dijunkunpw",
: "certs/crossdesk.cn_root.crt"; sizeof(params_.turn_server_password) - 1);
params_.log_path = dll_log_path_.c_str(); params_.turn_server_password[sizeof(params_.turn_server_password) - 1] = '\0';
params_.hardware_acceleration = config_center_.IsHardwareVideoCodec(); strncpy(params_.tls_cert_path, server_cert_path.c_str(),
params_.av1_encoding = config_center_.GetVideoEncodeFormat() == sizeof(params_.tls_cert_path) - 1);
params_.tls_cert_path[sizeof(params_.tls_cert_path) - 1] = '\0';
strncpy(params_.log_path, dll_log_path_.c_str(),
sizeof(params_.log_path) - 1);
params_.log_path[sizeof(params_.log_path) - 1] = '\0';
params_.hardware_acceleration = config_center_->IsHardwareVideoCodec();
params_.av1_encoding = config_center_->GetVideoEncodeFormat() ==
ConfigCenter::VIDEO_ENCODE_FORMAT::AV1 ConfigCenter::VIDEO_ENCODE_FORMAT::AV1
? true ? true
: false; : false;
params_.enable_turn = config_center_.IsEnableTurn(); params_.enable_turn = config_center_->IsEnableTurn();
params_.enable_srtp = config_center_.IsEnableSrtp(); params_.enable_srtp = config_center_->IsEnableSrtp();
params_.on_receive_video_buffer = nullptr; params_.on_receive_video_buffer = nullptr;
params_.on_receive_audio_buffer = OnReceiveAudioBufferCb; params_.on_receive_audio_buffer = OnReceiveAudioBufferCb;
params_.on_receive_data_buffer = OnReceiveDataBufferCb; params_.on_receive_data_buffer = OnReceiveDataBufferCb;
@@ -890,6 +870,20 @@ int Render::Run() {
exec_log_path_ = path_manager_->GetLogPath().string(); exec_log_path_ = path_manager_->GetLogPath().string();
dll_log_path_ = path_manager_->GetLogPath().string(); dll_log_path_ = path_manager_->GetLogPath().string();
cache_path_ = path_manager_->GetCachePath().string(); cache_path_ = path_manager_->GetCachePath().string();
config_center_ =
std::make_unique<ConfigCenter>(cache_path_ + "/config.ini", cert_path_);
strncpy(signal_server_ip_tmp_, config_center_->GetServerHost().c_str(),
sizeof(signal_server_ip_tmp_) - 1);
signal_server_ip_tmp_[sizeof(signal_server_ip_tmp_) - 1] = '\0';
strncpy(signal_server_port_tmp_,
std::to_string(config_center_->GetServerPort()).c_str(),
sizeof(signal_server_port_tmp_) - 1);
signal_server_port_tmp_[sizeof(signal_server_port_tmp_) - 1] = '\0';
strncpy(cert_file_path_, cert_path_.c_str(), sizeof(cert_file_path_) - 1);
cert_file_path_[sizeof(cert_file_path_) - 1] = '\0';
} else {
std::cerr << "Failed to create PathManager" << std::endl;
return -1;
} }
InitializeLogger(); InitializeLogger();

View File

@@ -263,7 +263,7 @@ class Render {
private: private:
CDCache cd_cache_; CDCache cd_cache_;
std::mutex cd_cache_mutex_; std::mutex cd_cache_mutex_;
ConfigCenter config_center_; std::unique_ptr<ConfigCenter> config_center_;
ConfigCenter::LANGUAGE localization_language_ = ConfigCenter::LANGUAGE localization_language_ =
ConfigCenter::LANGUAGE::CHINESE; ConfigCenter::LANGUAGE::CHINESE;
std::unique_ptr<PathManager> path_manager_; std::unique_ptr<PathManager> path_manager_;
@@ -357,9 +357,6 @@ class Render {
SDL_Event last_mouse_event; SDL_Event last_mouse_event;
SDL_AudioStream* output_stream_; SDL_AudioStream* output_stream_;
uint32_t STREAM_REFRESH_EVENT = 0; uint32_t STREAM_REFRESH_EVENT = 0;
char self_hosted_server_host_[256] = "";
char self_hosted_server_port_[6] = "";
char self_hosted_server_cert_path_[256] = "";
// stream window render // stream window render
SDL_Window* stream_window_ = nullptr; SDL_Window* stream_window_ = nullptr;
@@ -437,6 +434,9 @@ class Render {
bool enable_hardware_video_codec_ = false; bool enable_hardware_video_codec_ = false;
bool enable_turn_ = false; bool enable_turn_ = false;
bool enable_srtp_ = false; bool enable_srtp_ = false;
char signal_server_ip_[256] = "api.crossdesk.cn";
char signal_server_port_[6] = "9099";
char cert_file_path_[256] = "";
bool enable_self_hosted_server_ = false; bool enable_self_hosted_server_ = false;
int language_button_value_last_ = 0; int language_button_value_last_ = 0;
int video_quality_button_value_last_ = 0; int video_quality_button_value_last_ = 0;
@@ -444,6 +444,8 @@ class Render {
bool enable_hardware_video_codec_last_ = false; bool enable_hardware_video_codec_last_ = false;
bool enable_turn_last_ = false; bool enable_turn_last_ = false;
bool enable_srtp_last_ = false; bool enable_srtp_last_ = false;
char signal_server_ip_tmp_[256] = "api.crossdesk.cn";
char signal_server_port_tmp_[6] = "9099";
bool settings_window_pos_reset_ = true; bool settings_window_pos_reset_ = true;
bool self_hosted_server_config_window_pos_reset_ = true; bool self_hosted_server_config_window_pos_reset_ = true;
std::string selected_current_file_path_ = ""; std::string selected_current_file_path_ = "";

View File

@@ -1,4 +1,4 @@
#include "layout_style.h" #include "layout.h"
#include "localization.h" #include "localization.h"
#include "rd_log.h" #include "rd_log.h"
#include "render.h" #include "render.h"

View File

@@ -1,4 +1,4 @@
#include "layout_style.h" #include "layout.h"
#include "localization.h" #include "localization.h"
#include "rd_log.h" #include "rd_log.h"
#include "render.h" #include "render.h"

View File

@@ -1,4 +1,4 @@
#include "layout_style.h" #include "layout.h"
#include "localization.h" #include "localization.h"
#include "rd_log.h" #include "rd_log.h"
#include "render.h" #include "render.h"

View File

@@ -1,4 +1,4 @@
#include "layout_style.h" #include "layout.h"
#include "localization.h" #include "localization.h"
#include "rd_log.h" #include "rd_log.h"
#include "render.h" #include "render.h"
@@ -108,7 +108,7 @@ int Render::SettingWindow() {
ImGui::Separator(); ImGui::Separator();
{ {
const char* video_frame_rate_items[] = {"30", "60"}; const char* video_frame_rate_items[] = {"30 fps", "60 fps"};
settings_items_offset += settings_items_padding; settings_items_offset += settings_items_padding;
ImGui::SetCursorPosY(settings_items_offset + 2); ImGui::SetCursorPosY(settings_items_offset + 2);
@@ -133,8 +133,8 @@ int Render::SettingWindow() {
{ {
const char* video_encode_format_items[] = { const char* video_encode_format_items[] = {
localization::av1[localization_language_index_].c_str(), localization::h264[localization_language_index_].c_str(),
localization::h264[localization_language_index_].c_str()}; localization::av1[localization_language_index_].c_str()};
settings_items_offset += settings_items_padding; settings_items_offset += settings_items_padding;
ImGui::SetCursorPosY(settings_items_offset + 2); ImGui::SetCursorPosY(settings_items_offset + 2);
@@ -255,9 +255,9 @@ int Render::SettingWindow() {
// Language // Language
if (language_button_value_ == 0) { if (language_button_value_ == 0) {
config_center_.SetLanguage(ConfigCenter::LANGUAGE::CHINESE); config_center_->SetLanguage(ConfigCenter::LANGUAGE::CHINESE);
} else { } else {
config_center_.SetLanguage(ConfigCenter::LANGUAGE::ENGLISH); config_center_->SetLanguage(ConfigCenter::LANGUAGE::ENGLISH);
} }
language_button_value_last_ = language_button_value_; language_button_value_last_ = language_button_value_;
localization_language_ = (ConfigCenter::LANGUAGE)language_button_value_; localization_language_ = (ConfigCenter::LANGUAGE)language_button_value_;
@@ -267,50 +267,55 @@ int Render::SettingWindow() {
// Video quality // Video quality
if (video_quality_button_value_ == 0) { if (video_quality_button_value_ == 0) {
config_center_.SetVideoQuality(ConfigCenter::VIDEO_QUALITY::HIGH); config_center_->SetVideoQuality(ConfigCenter::VIDEO_QUALITY::HIGH);
} else if (video_quality_button_value_ == 1) { } else if (video_quality_button_value_ == 1) {
config_center_.SetVideoQuality(ConfigCenter::VIDEO_QUALITY::MEDIUM); config_center_->SetVideoQuality(ConfigCenter::VIDEO_QUALITY::MEDIUM);
} else { } else {
config_center_.SetVideoQuality(ConfigCenter::VIDEO_QUALITY::LOW); config_center_->SetVideoQuality(ConfigCenter::VIDEO_QUALITY::LOW);
} }
video_quality_button_value_last_ = video_quality_button_value_; video_quality_button_value_last_ = video_quality_button_value_;
// Video encode format // Video encode format
if (video_encode_format_button_value_ == 0) { if (video_encode_format_button_value_ == 0) {
config_center_.SetVideoEncodeFormat( config_center_->SetVideoEncodeFormat(
ConfigCenter::VIDEO_ENCODE_FORMAT::AV1);
} else if (video_encode_format_button_value_ == 1) {
config_center_.SetVideoEncodeFormat(
ConfigCenter::VIDEO_ENCODE_FORMAT::H264); ConfigCenter::VIDEO_ENCODE_FORMAT::H264);
} else if (video_encode_format_button_value_ == 1) {
config_center_->SetVideoEncodeFormat(
ConfigCenter::VIDEO_ENCODE_FORMAT::AV1);
} }
video_encode_format_button_value_last_ = video_encode_format_button_value_last_ =
video_encode_format_button_value_; video_encode_format_button_value_;
// Hardware video codec // Hardware video codec
if (enable_hardware_video_codec_) { if (enable_hardware_video_codec_) {
config_center_.SetHardwareVideoCodec(true); config_center_->SetHardwareVideoCodec(true);
} else { } else {
config_center_.SetHardwareVideoCodec(false); config_center_->SetHardwareVideoCodec(false);
} }
enable_hardware_video_codec_last_ = enable_hardware_video_codec_; enable_hardware_video_codec_last_ = enable_hardware_video_codec_;
// TURN mode // TURN mode
if (enable_turn_) { if (enable_turn_) {
config_center_.SetTurn(true); config_center_->SetTurn(true);
} else { } else {
config_center_.SetTurn(false); config_center_->SetTurn(false);
} }
enable_turn_last_ = enable_turn_; enable_turn_last_ = enable_turn_;
// SRTP // SRTP
if (enable_srtp_) { if (enable_srtp_) {
config_center_.SetSrtp(true); config_center_->SetSrtp(true);
} else { } else {
config_center_.SetSrtp(false); config_center_->SetSrtp(false);
} }
enable_srtp_last_ = enable_srtp_; enable_srtp_last_ = enable_srtp_;
SaveSettingsIntoCacheFile(); if (enable_self_hosted_server_) {
config_center_->SetSelfHosted(true);
} else {
config_center_->SetSelfHosted(false);
}
settings_window_pos_reset_ = true; settings_window_pos_reset_ = true;
// Recreate peer instance // Recreate peer instance

View File

@@ -5,7 +5,7 @@
#include <windows.h> #include <windows.h>
#endif #endif
#include "layout_style.h" #include "layout.h"
#include "localization.h" #include "localization.h"
#include "rd_log.h" #include "rd_log.h"
#include "render.h" #include "render.h"
@@ -157,8 +157,9 @@ int Render::SelfHostedServerWindow() {
ImGui::SetCursorPosY(settings_items_offset); ImGui::SetCursorPosY(settings_items_offset);
ImGui::SetNextItemWidth(SELF_HOSTED_SERVER_INPUT_WINDOW_WIDTH); ImGui::SetNextItemWidth(SELF_HOSTED_SERVER_INPUT_WINDOW_WIDTH);
ImGui::InputText("##self_hosted_server_host_", self_hosted_server_host_, ImGui::InputText("##signal_server_ip_tmp_", signal_server_ip_tmp_,
IM_ARRAYSIZE(self_hosted_server_host_)); IM_ARRAYSIZE(signal_server_ip_tmp_),
ImGuiInputTextFlags_AlwaysOverwrite);
} }
ImGui::Separator(); ImGui::Separator();
@@ -179,8 +180,8 @@ int Render::SelfHostedServerWindow() {
ImGui::SetCursorPosY(settings_items_offset); ImGui::SetCursorPosY(settings_items_offset);
ImGui::SetNextItemWidth(SELF_HOSTED_SERVER_INPUT_WINDOW_WIDTH); ImGui::SetNextItemWidth(SELF_HOSTED_SERVER_INPUT_WINDOW_WIDTH);
ImGui::InputText("##self_hosted_server_port_", self_hosted_server_port_, ImGui::InputText("##signal_server_port_tmp_", signal_server_port_tmp_,
IM_ARRAYSIZE(self_hosted_server_port_)); IM_ARRAYSIZE(signal_server_port_tmp_));
} }
ImGui::Separator(); ImGui::Separator();
@@ -222,75 +223,20 @@ int Render::SelfHostedServerWindow() {
localization::ok[localization_language_index_].c_str())) { localization::ok[localization_language_index_].c_str())) {
show_self_hosted_server_config_window_ = false; show_self_hosted_server_config_window_ = false;
// Language config_center_->SetServerHost(signal_server_ip_tmp_);
if (language_button_value_ == 0) { config_center_->SetServerPort(atoi(signal_server_port_tmp_));
config_center_.SetLanguage(ConfigCenter::LANGUAGE::CHINESE); config_center_->SetCertFilePath(selected_file_);
} else { strncpy(signal_server_ip_, signal_server_ip_tmp_,
config_center_.SetLanguage(ConfigCenter::LANGUAGE::ENGLISH); sizeof(signal_server_ip_) - 1);
} signal_server_ip_[sizeof(signal_server_ip_) - 1] = '\0';
language_button_value_last_ = language_button_value_; strncpy(signal_server_port_, signal_server_port_tmp_,
localization_language_ = (ConfigCenter::LANGUAGE)language_button_value_; sizeof(signal_server_port_) - 1);
localization_language_index_ = language_button_value_; signal_server_port_[sizeof(signal_server_port_) - 1] = '\0';
LOG_INFO("Set localization language: {}", strncpy(cert_file_path_, selected_file_.c_str(),
localization_language_index_ == 0 ? "zh" : "en"); sizeof(cert_file_path_) - 1);
cert_file_path_[sizeof(cert_file_path_) - 1] = '\0';
// Video quality
if (video_quality_button_value_ == 0) {
config_center_.SetVideoQuality(ConfigCenter::VIDEO_QUALITY::HIGH);
} else if (video_quality_button_value_ == 1) {
config_center_.SetVideoQuality(ConfigCenter::VIDEO_QUALITY::MEDIUM);
} else {
config_center_.SetVideoQuality(ConfigCenter::VIDEO_QUALITY::LOW);
}
video_quality_button_value_last_ = video_quality_button_value_;
// Video encode format
if (video_encode_format_button_value_ == 0) {
config_center_.SetVideoEncodeFormat(
ConfigCenter::VIDEO_ENCODE_FORMAT::AV1);
} else if (video_encode_format_button_value_ == 1) {
config_center_.SetVideoEncodeFormat(
ConfigCenter::VIDEO_ENCODE_FORMAT::H264);
}
video_encode_format_button_value_last_ =
video_encode_format_button_value_;
// Hardware video codec
if (enable_hardware_video_codec_) {
config_center_.SetHardwareVideoCodec(true);
} else {
config_center_.SetHardwareVideoCodec(false);
}
enable_hardware_video_codec_last_ = enable_hardware_video_codec_;
// TURN mode
if (enable_turn_) {
config_center_.SetTurn(true);
} else {
config_center_.SetTurn(false);
}
enable_turn_last_ = enable_turn_;
// SRTP
if (enable_srtp_) {
config_center_.SetSrtp(true);
} else {
config_center_.SetSrtp(false);
}
enable_srtp_last_ = enable_srtp_;
SaveSettingsIntoCacheFile();
self_hosted_server_config_window_pos_reset_ = true; self_hosted_server_config_window_pos_reset_ = true;
// Recreate peer instance
LoadSettingsFromCacheFile();
// Recreate peer instance
if (!stream_window_inited_) {
LOG_INFO("Recreate peer instance");
CleanupPeers();
CreateConnectionPeer();
}
} }
ImGui::SameLine(); ImGui::SameLine();
@@ -298,30 +244,19 @@ int Render::SelfHostedServerWindow() {
if (ImGui::Button( if (ImGui::Button(
localization::cancel[localization_language_index_].c_str())) { localization::cancel[localization_language_index_].c_str())) {
show_self_hosted_server_config_window_ = false; show_self_hosted_server_config_window_ = false;
if (language_button_value_ != language_button_value_last_) {
language_button_value_ = language_button_value_last_;
}
if (video_quality_button_value_ != video_quality_button_value_last_) {
video_quality_button_value_ = video_quality_button_value_last_;
}
if (video_encode_format_button_value_ !=
video_encode_format_button_value_last_) {
video_encode_format_button_value_ =
video_encode_format_button_value_last_;
}
if (enable_hardware_video_codec_ != enable_hardware_video_codec_last_) {
enable_hardware_video_codec_ = enable_hardware_video_codec_last_;
}
if (enable_turn_ != enable_turn_last_) {
enable_turn_ = enable_turn_last_;
}
self_hosted_server_config_window_pos_reset_ = true; self_hosted_server_config_window_pos_reset_ = true;
strncpy(signal_server_ip_tmp_, signal_server_ip_,
sizeof(signal_server_ip_tmp_) - 1);
signal_server_ip_tmp_[sizeof(signal_server_ip_tmp_) - 1] = '\0';
strncpy(signal_server_port_tmp_, signal_server_port_,
sizeof(signal_server_port_tmp_) - 1);
signal_server_port_tmp_[sizeof(signal_server_port_tmp_) - 1] = '\0';
config_center_->SetServerHost(signal_server_ip_tmp_);
config_center_->SetServerPort(atoi(signal_server_port_tmp_));
selected_file_.clear();
} }
ImGui::SetWindowFontScale(1.0f); ImGui::SetWindowFontScale(1.0f);
ImGui::SetWindowFontScale(0.5f); ImGui::SetWindowFontScale(0.5f);
ImGui::End(); ImGui::End();

View File

@@ -120,26 +120,38 @@ target("device_controller")
"src/device_controller/keyboard/linux", {public = true}) "src/device_controller/keyboard/linux", {public = true})
end end
target("thumbnail")
set_kind("object")
add_packages("libyuv", "openssl3")
add_deps("rd_log", "common")
add_files("src/thumbnail/*.cpp")
add_includedirs("src/thumbnail", {public = true})
target("config_center") target("config_center")
set_kind("object") set_kind("object")
add_deps("rd_log") add_deps("rd_log")
add_files("src/config_center/*.cpp") add_files("src/config_center/*.cpp")
add_includedirs("src/config_center", {public = true}) add_includedirs("src/config_center", {public = true})
target("localization") target("assets")
set_kind("headeronly") set_kind("headeronly")
add_includedirs("src/localization", {public = true}) add_includedirs("src/gui/assets/localization",
"src/gui/assets/fonts",
"src/gui/assets/icons",
"src/gui/assets/layouts", {public = true})
target("single_window") target("gui")
set_kind("object") set_kind("object")
add_packages("libyuv", "openssl3") add_packages("libyuv")
add_deps("rd_log", "common", "localization", "config_center", "minirtc", add_deps("rd_log", "common", "assets", "config_center", "minirtc",
"path_manager", "screen_capturer", "speaker_capturer", "device_controller") "path_manager", "screen_capturer", "speaker_capturer",
add_files("src/single_window/*.cpp") "device_controller", "thumbnail")
add_includedirs("src/single_window", {public = true}) add_files("src/gui/*.cpp", "src/gui/panels/*.cpp", "src/gui/toolbars/*.cpp",
add_includedirs("fonts", {public = true}) "src/gui/windows/*.cpp")
add_includedirs("src/gui", "src/gui/panels", "src/gui/toolbars",
"src/gui/windows", {public = true})
target("crossdesk") target("crossdesk")
set_kind("binary") set_kind("binary")
add_deps("rd_log", "common", "single_window") add_deps("rd_log", "common", "gui")
add_files("src/gui/main.cpp") add_files("src/app/main.cpp")