[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 "rd_log.h"
ConfigCenter::ConfigCenter() {}
ConfigCenter::ConfigCenter(const std::string& config_path,
const std::string& cert_file_path)
: config_path_(config_path),
cert_file_path_(cert_file_path),
cert_file_path_default_(cert_file_path) {
ini_.SetUnicode(true);
Load();
}
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) {
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;
}
int ConfigCenter::SetVideoQuality(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;
}
int ConfigCenter::SetVideoFrameRate(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;
}
int ConfigCenter::SetVideoEncodeFormat(
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;
}
int ConfigCenter::SetHardwareVideoCodec(bool 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;
}
int ConfigCenter::SetTurn(bool 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;
}
int ConfigCenter::SetSrtp(bool 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;
}
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_;
}
int ConfigCenter::GetVideoFrameRate() {
int fps = video_frame_rate_ == VIDEO_FRAME_RATE::FPS_30 ? 30 : 60;
return fps;
ConfigCenter::VIDEO_FRAME_RATE ConfigCenter::GetVideoFrameRate() const {
return video_frame_rate_;
}
ConfigCenter::VIDEO_ENCODE_FORMAT ConfigCenter::GetVideoEncodeFormat() {
ConfigCenter::VIDEO_ENCODE_FORMAT ConfigCenter::GetVideoEncodeFormat() const {
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_
#define _CONFIG_CENTER_H_
#include <string>
#include "SimpleIni.h"
class ConfigCenter {
public:
enum class LANGUAGE { CHINESE = 0, ENGLISH = 1 };
enum class VIDEO_QUALITY { LOW = 0, MEDIUM = 1, HIGH = 2 };
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:
ConfigCenter();
explicit ConfigCenter(
const std::string& config_path = "config.ini",
const std::string& cert_file_path = "crossdesk.cn_root.crt");
~ConfigCenter();
public:
// write config
int SetLanguage(LANGUAGE language);
int SetVideoQuality(VIDEO_QUALITY video_quality);
int SetVideoFrameRate(VIDEO_FRAME_RATE video_frame_rate);
@@ -26,25 +32,50 @@ class ConfigCenter {
int SetHardwareVideoCodec(bool hardware_video_codec);
int SetTurn(bool enable_turn);
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:
LANGUAGE GetLanguage();
VIDEO_QUALITY GetVideoQuality();
int GetVideoFrameRate();
VIDEO_ENCODE_FORMAT GetVideoEncodeFormat();
bool IsHardwareVideoCodec();
bool IsEnableTurn();
bool IsEnableSrtp();
// read config
LANGUAGE GetLanguage() const;
VIDEO_QUALITY GetVideoQuality() const;
VIDEO_FRAME_RATE GetVideoFrameRate() const;
VIDEO_ENCODE_FORMAT GetVideoEncodeFormat() const;
bool IsHardwareVideoCodec() const;
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:
// 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;
VIDEO_QUALITY video_quality_ = VIDEO_QUALITY::MEDIUM;
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 enable_turn_ = 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

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

@@ -11,7 +11,7 @@
#include "device_controller_factory.h"
#include "fa_regular_400.h"
#include "fa_solid_900.h"
#include "layout_style.h"
#include "layout.h"
#include "localization.h"
#include "platform.h"
#include "rd_log.h"
@@ -171,7 +171,8 @@ Render::~Render() {}
int Render::SaveSettingsIntoCacheFile() {
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) {
cd_cache_mutex_.unlock();
return -1;
@@ -181,18 +182,6 @@ int Render::SaveSettingsIntoCacheFile() {
sizeof(cd_cache_.client_id_with_password));
memcpy(cd_cache_.client_id_with_password, 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_.iv, &aes128_iv_, sizeof(aes128_iv_));
@@ -200,49 +189,19 @@ int Render::SaveSettingsIntoCacheFile() {
cd_cache_file.close();
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;
}
int Render::LoadSettingsFromCacheFile() {
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) {
cd_cache_mutex_.unlock();
LOG_INFO("Init cache file by using default settings");
memset(password_saved_, 0, sizeof(password_saved_));
memset(aes128_key_, 0, sizeof(aes128_key_));
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_ = std::make_unique<Thumbnail>(cache_path_ + "/thumbnails/");
@@ -289,13 +248,14 @@ int Render::LoadSettingsFromCacheFile() {
thumbnail_ = std::make_unique<Thumbnail>(cache_path_ + "/thumbnails/",
aes128_key_, aes128_iv_);
language_button_value_ = cd_cache_.language;
video_quality_button_value_ = cd_cache_.video_quality;
video_frame_rate_button_value_ = cd_cache_.video_frame_rate;
video_encode_format_button_value_ = cd_cache_.video_encode_format;
enable_hardware_video_codec_ = cd_cache_.enable_hardware_video_codec;
enable_turn_ = cd_cache_.enable_turn;
enable_srtp_ = cd_cache_.enable_srtp;
language_button_value_ = (int)config_center_->GetLanguage();
video_quality_button_value_ = (int)config_center_->GetVideoQuality();
video_frame_rate_button_value_ = (int)config_center_->GetVideoFrameRate();
video_encode_format_button_value_ =
(int)config_center_->GetVideoEncodeFormat();
enable_hardware_video_codec_ = config_center_->IsHardwareVideoCodec();
enable_turn_ = config_center_->IsEnableTurn();
enable_srtp_ = config_center_->IsEnableSrtp();
language_button_value_last_ = language_button_value_;
video_quality_button_value_last_ = video_quality_button_value_;
@@ -304,17 +264,6 @@ int Render::LoadSettingsFromCacheFile() {
enable_turn_last_ = enable_turn_;
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");
return 0;
@@ -328,18 +277,21 @@ int Render::ScreenCapturerInit() {
last_frame_time_ = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now().time_since_epoch())
.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);
int screen_capturer_init_ret = screen_capturer_->Init(
fps,
[this](unsigned char* data, int size, int width, int height,
const char* display_name) -> void {
[this, fps](unsigned char* data, int size, int width, int height,
const char* display_name) -> void {
auto now_time = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now().time_since_epoch())
.count();
auto duration = now_time - last_frame_time_;
if (duration * config_center_.GetVideoFrameRate() >= 1000) { // ~60 FPS
if (duration * fps >= 1000) { // ~60 FPS
XVideoFrame frame;
frame.data = (const char*)data;
frame.size = size;
@@ -474,25 +426,53 @@ int Render::StopKeyboardCapturer() {
int Render::CreateConnectionPeer() {
params_.use_cfg_file = false;
params_.signal_server_ip = "api.crossdesk.cn";
params_.signal_server_port = 9099;
params_.stun_server_ip = "150.158.81.30";
std::string server_ip;
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_.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_username = "dijunkun";
params_.turn_server_password = "dijunkunpw";
params_.tls_cert_path = std::filesystem::exists(cert_path_)
? cert_path_.c_str()
: "certs/crossdesk.cn_root.crt";
params_.log_path = dll_log_path_.c_str();
params_.hardware_acceleration = config_center_.IsHardwareVideoCodec();
params_.av1_encoding = config_center_.GetVideoEncodeFormat() ==
strncpy((char*)params_.turn_server_username, "dijunkun",
sizeof(params_.turn_server_username) - 1);
params_.turn_server_username[sizeof(params_.turn_server_username) - 1] = '\0';
strncpy((char*)params_.turn_server_password, "dijunkunpw",
sizeof(params_.turn_server_password) - 1);
params_.turn_server_password[sizeof(params_.turn_server_password) - 1] = '\0';
strncpy(params_.tls_cert_path, server_cert_path.c_str(),
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
? true
: false;
params_.enable_turn = config_center_.IsEnableTurn();
params_.enable_srtp = config_center_.IsEnableSrtp();
params_.enable_turn = config_center_->IsEnableTurn();
params_.enable_srtp = config_center_->IsEnableSrtp();
params_.on_receive_video_buffer = nullptr;
params_.on_receive_audio_buffer = OnReceiveAudioBufferCb;
params_.on_receive_data_buffer = OnReceiveDataBufferCb;
@@ -890,6 +870,20 @@ int Render::Run() {
exec_log_path_ = path_manager_->GetLogPath().string();
dll_log_path_ = path_manager_->GetLogPath().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();

View File

@@ -263,7 +263,7 @@ class Render {
private:
CDCache cd_cache_;
std::mutex cd_cache_mutex_;
ConfigCenter config_center_;
std::unique_ptr<ConfigCenter> config_center_;
ConfigCenter::LANGUAGE localization_language_ =
ConfigCenter::LANGUAGE::CHINESE;
std::unique_ptr<PathManager> path_manager_;
@@ -357,9 +357,6 @@ class Render {
SDL_Event last_mouse_event;
SDL_AudioStream* output_stream_;
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
SDL_Window* stream_window_ = nullptr;
@@ -437,6 +434,9 @@ class Render {
bool enable_hardware_video_codec_ = false;
bool enable_turn_ = 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;
int language_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_turn_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 self_hosted_server_config_window_pos_reset_ = true;
std::string selected_current_file_path_ = "";

View File

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

View File

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

View File

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

View File

@@ -1,4 +1,4 @@
#include "layout_style.h"
#include "layout.h"
#include "localization.h"
#include "rd_log.h"
#include "render.h"
@@ -108,7 +108,7 @@ int Render::SettingWindow() {
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;
ImGui::SetCursorPosY(settings_items_offset + 2);
@@ -133,8 +133,8 @@ int Render::SettingWindow() {
{
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;
ImGui::SetCursorPosY(settings_items_offset + 2);
@@ -255,9 +255,9 @@ int Render::SettingWindow() {
// Language
if (language_button_value_ == 0) {
config_center_.SetLanguage(ConfigCenter::LANGUAGE::CHINESE);
config_center_->SetLanguage(ConfigCenter::LANGUAGE::CHINESE);
} else {
config_center_.SetLanguage(ConfigCenter::LANGUAGE::ENGLISH);
config_center_->SetLanguage(ConfigCenter::LANGUAGE::ENGLISH);
}
language_button_value_last_ = language_button_value_;
localization_language_ = (ConfigCenter::LANGUAGE)language_button_value_;
@@ -267,50 +267,55 @@ int Render::SettingWindow() {
// Video quality
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) {
config_center_.SetVideoQuality(ConfigCenter::VIDEO_QUALITY::MEDIUM);
config_center_->SetVideoQuality(ConfigCenter::VIDEO_QUALITY::MEDIUM);
} 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 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(
config_center_->SetVideoEncodeFormat(
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_;
// Hardware video codec
if (enable_hardware_video_codec_) {
config_center_.SetHardwareVideoCodec(true);
config_center_->SetHardwareVideoCodec(true);
} else {
config_center_.SetHardwareVideoCodec(false);
config_center_->SetHardwareVideoCodec(false);
}
enable_hardware_video_codec_last_ = enable_hardware_video_codec_;
// TURN mode
if (enable_turn_) {
config_center_.SetTurn(true);
config_center_->SetTurn(true);
} else {
config_center_.SetTurn(false);
config_center_->SetTurn(false);
}
enable_turn_last_ = enable_turn_;
// SRTP
if (enable_srtp_) {
config_center_.SetSrtp(true);
config_center_->SetSrtp(true);
} else {
config_center_.SetSrtp(false);
config_center_->SetSrtp(false);
}
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;
// Recreate peer instance

View File

@@ -5,7 +5,7 @@
#include <windows.h>
#endif
#include "layout_style.h"
#include "layout.h"
#include "localization.h"
#include "rd_log.h"
#include "render.h"
@@ -157,8 +157,9 @@ int Render::SelfHostedServerWindow() {
ImGui::SetCursorPosY(settings_items_offset);
ImGui::SetNextItemWidth(SELF_HOSTED_SERVER_INPUT_WINDOW_WIDTH);
ImGui::InputText("##self_hosted_server_host_", self_hosted_server_host_,
IM_ARRAYSIZE(self_hosted_server_host_));
ImGui::InputText("##signal_server_ip_tmp_", signal_server_ip_tmp_,
IM_ARRAYSIZE(signal_server_ip_tmp_),
ImGuiInputTextFlags_AlwaysOverwrite);
}
ImGui::Separator();
@@ -179,8 +180,8 @@ int Render::SelfHostedServerWindow() {
ImGui::SetCursorPosY(settings_items_offset);
ImGui::SetNextItemWidth(SELF_HOSTED_SERVER_INPUT_WINDOW_WIDTH);
ImGui::InputText("##self_hosted_server_port_", self_hosted_server_port_,
IM_ARRAYSIZE(self_hosted_server_port_));
ImGui::InputText("##signal_server_port_tmp_", signal_server_port_tmp_,
IM_ARRAYSIZE(signal_server_port_tmp_));
}
ImGui::Separator();
@@ -222,75 +223,20 @@ int Render::SelfHostedServerWindow() {
localization::ok[localization_language_index_].c_str())) {
show_self_hosted_server_config_window_ = false;
// Language
if (language_button_value_ == 0) {
config_center_.SetLanguage(ConfigCenter::LANGUAGE::CHINESE);
} else {
config_center_.SetLanguage(ConfigCenter::LANGUAGE::ENGLISH);
}
language_button_value_last_ = language_button_value_;
localization_language_ = (ConfigCenter::LANGUAGE)language_button_value_;
localization_language_index_ = language_button_value_;
LOG_INFO("Set localization language: {}",
localization_language_index_ == 0 ? "zh" : "en");
config_center_->SetServerHost(signal_server_ip_tmp_);
config_center_->SetServerPort(atoi(signal_server_port_tmp_));
config_center_->SetCertFilePath(selected_file_);
strncpy(signal_server_ip_, signal_server_ip_tmp_,
sizeof(signal_server_ip_) - 1);
signal_server_ip_[sizeof(signal_server_ip_) - 1] = '\0';
strncpy(signal_server_port_, signal_server_port_tmp_,
sizeof(signal_server_port_) - 1);
signal_server_port_[sizeof(signal_server_port_) - 1] = '\0';
strncpy(cert_file_path_, selected_file_.c_str(),
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;
// Recreate peer instance
LoadSettingsFromCacheFile();
// Recreate peer instance
if (!stream_window_inited_) {
LOG_INFO("Recreate peer instance");
CleanupPeers();
CreateConnectionPeer();
}
}
ImGui::SameLine();
@@ -298,30 +244,19 @@ int Render::SelfHostedServerWindow() {
if (ImGui::Button(
localization::cancel[localization_language_index_].c_str())) {
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;
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(0.5f);
ImGui::End();