mirror of
https://github.com/kunkundi/crossdesk.git
synced 2026-07-22 23:28:48 +08:00
[feat] add TURN relay mode configuration
This commit is contained in:
@@ -5,6 +5,15 @@
|
|||||||
|
|
||||||
namespace crossdesk {
|
namespace crossdesk {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
bool IsValidTurnModeValue(long value) {
|
||||||
|
return value >= static_cast<long>(ConfigCenter::TURN_MODE::DISABLED) &&
|
||||||
|
value <= static_cast<long>(ConfigCenter::TURN_MODE::FORCE_TCP);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
ConfigCenter::ConfigCenter(const std::string& config_path)
|
ConfigCenter::ConfigCenter(const std::string& config_path)
|
||||||
: config_path_(config_path) {
|
: config_path_(config_path) {
|
||||||
ini_.SetUnicode(true);
|
ini_.SetUnicode(true);
|
||||||
@@ -20,6 +29,8 @@ int ConfigCenter::Load() {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool persist_turn_mode_migration = false;
|
||||||
|
|
||||||
const long language_value =
|
const long language_value =
|
||||||
ini_.GetLongValue(section_, "language", static_cast<long>(language_));
|
ini_.GetLongValue(section_, "language", static_cast<long>(language_));
|
||||||
if (language_value < static_cast<long>(LANGUAGE::CHINESE) ||
|
if (language_value < static_cast<long>(LANGUAGE::CHINESE) ||
|
||||||
@@ -42,7 +53,25 @@ int ConfigCenter::Load() {
|
|||||||
hardware_video_codec_ = ini_.GetBoolValue(section_, "hardware_video_codec",
|
hardware_video_codec_ = ini_.GetBoolValue(section_, "hardware_video_codec",
|
||||||
hardware_video_codec_);
|
hardware_video_codec_);
|
||||||
|
|
||||||
enable_turn_ = ini_.GetBoolValue(section_, "enable_turn", enable_turn_);
|
const char* turn_mode_value = ini_.GetValue(section_, "turn_mode", nullptr);
|
||||||
|
if (turn_mode_value != nullptr && strlen(turn_mode_value) > 0) {
|
||||||
|
const long parsed_turn_mode = ini_.GetLongValue(
|
||||||
|
section_, "turn_mode", static_cast<long>(turn_mode_));
|
||||||
|
if (IsValidTurnModeValue(parsed_turn_mode)) {
|
||||||
|
turn_mode_ = static_cast<TURN_MODE>(parsed_turn_mode);
|
||||||
|
} else {
|
||||||
|
LOG_WARN("Invalid TURN mode [{}], using auto UDP/TCP",
|
||||||
|
parsed_turn_mode);
|
||||||
|
turn_mode_ = TURN_MODE::AUTO_UDP_TCP;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const bool legacy_enable_turn = ini_.GetBoolValue(
|
||||||
|
section_, "enable_turn", turn_mode_ != TURN_MODE::DISABLED);
|
||||||
|
turn_mode_ = legacy_enable_turn ? TURN_MODE::AUTO_UDP_TCP
|
||||||
|
: TURN_MODE::DISABLED;
|
||||||
|
ini_.SetLongValue(section_, "turn_mode", static_cast<long>(turn_mode_));
|
||||||
|
persist_turn_mode_migration = true;
|
||||||
|
}
|
||||||
enable_srtp_ = ini_.GetBoolValue(section_, "enable_srtp", enable_srtp_);
|
enable_srtp_ = ini_.GetBoolValue(section_, "enable_srtp", enable_srtp_);
|
||||||
enable_self_hosted_ =
|
enable_self_hosted_ =
|
||||||
ini_.GetBoolValue(section_, "enable_self_hosted", enable_self_hosted_);
|
ini_.GetBoolValue(section_, "enable_self_hosted", enable_self_hosted_);
|
||||||
@@ -92,6 +121,11 @@ int ConfigCenter::Load() {
|
|||||||
file_transfer_save_path_ = "";
|
file_transfer_save_path_ = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (persist_turn_mode_migration &&
|
||||||
|
ini_.SaveFile(config_path_.c_str()) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +138,9 @@ int ConfigCenter::Save() {
|
|||||||
ini_.SetLongValue(section_, "video_encode_format",
|
ini_.SetLongValue(section_, "video_encode_format",
|
||||||
static_cast<long>(video_encode_format_));
|
static_cast<long>(video_encode_format_));
|
||||||
ini_.SetBoolValue(section_, "hardware_video_codec", hardware_video_codec_);
|
ini_.SetBoolValue(section_, "hardware_video_codec", hardware_video_codec_);
|
||||||
ini_.SetBoolValue(section_, "enable_turn", enable_turn_);
|
ini_.SetLongValue(section_, "turn_mode", static_cast<long>(turn_mode_));
|
||||||
|
ini_.SetBoolValue(section_, "enable_turn",
|
||||||
|
turn_mode_ != TURN_MODE::DISABLED);
|
||||||
ini_.SetBoolValue(section_, "enable_srtp", enable_srtp_);
|
ini_.SetBoolValue(section_, "enable_srtp", enable_srtp_);
|
||||||
ini_.SetBoolValue(section_, "enable_self_hosted", enable_self_hosted_);
|
ini_.SetBoolValue(section_, "enable_self_hosted", enable_self_hosted_);
|
||||||
|
|
||||||
@@ -191,9 +227,15 @@ int ConfigCenter::SetHardwareVideoCodec(bool hardware_video_codec) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConfigCenter::SetTurn(bool enable_turn) {
|
int ConfigCenter::SetTurnMode(TURN_MODE turn_mode) {
|
||||||
enable_turn_ = enable_turn;
|
if (!IsValidTurnModeValue(static_cast<long>(turn_mode))) {
|
||||||
ini_.SetBoolValue(section_, "enable_turn", enable_turn_);
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
turn_mode_ = turn_mode;
|
||||||
|
ini_.SetLongValue(section_, "turn_mode", static_cast<long>(turn_mode_));
|
||||||
|
ini_.SetBoolValue(section_, "enable_turn",
|
||||||
|
turn_mode_ != TURN_MODE::DISABLED);
|
||||||
SI_Error rc = ini_.SaveFile(config_path_.c_str());
|
SI_Error rc = ini_.SaveFile(config_path_.c_str());
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
@@ -201,6 +243,16 @@ int ConfigCenter::SetTurn(bool enable_turn) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ConfigCenter::SetTurn(bool enable_turn) {
|
||||||
|
if (!enable_turn) {
|
||||||
|
return SetTurnMode(TURN_MODE::DISABLED);
|
||||||
|
}
|
||||||
|
if (turn_mode_ == TURN_MODE::DISABLED) {
|
||||||
|
return SetTurnMode(TURN_MODE::AUTO_UDP_TCP);
|
||||||
|
}
|
||||||
|
return SetTurnMode(turn_mode_);
|
||||||
|
}
|
||||||
|
|
||||||
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_);
|
ini_.SetBoolValue(section_, "enable_srtp", enable_srtp_);
|
||||||
@@ -362,7 +414,13 @@ bool ConfigCenter::IsHardwareVideoCodec() const {
|
|||||||
return hardware_video_codec_;
|
return hardware_video_codec_;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfigCenter::IsEnableTurn() const { return enable_turn_; }
|
ConfigCenter::TURN_MODE ConfigCenter::GetTurnMode() const {
|
||||||
|
return turn_mode_;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ConfigCenter::IsEnableTurn() const {
|
||||||
|
return turn_mode_ != TURN_MODE::DISABLED;
|
||||||
|
}
|
||||||
|
|
||||||
bool ConfigCenter::IsEnableSrtp() const { return enable_srtp_; }
|
bool ConfigCenter::IsEnableSrtp() const { return enable_srtp_; }
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,12 @@ class ConfigCenter {
|
|||||||
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 { H264 = 0, AV1 = 1 };
|
enum class VIDEO_ENCODE_FORMAT { H264 = 0, AV1 = 1 };
|
||||||
|
enum class TURN_MODE {
|
||||||
|
DISABLED = 0,
|
||||||
|
AUTO_UDP_TCP = 1,
|
||||||
|
FORCE_UDP = 2,
|
||||||
|
FORCE_TCP = 3
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ConfigCenter(const std::string& config_path = "config.ini");
|
explicit ConfigCenter(const std::string& config_path = "config.ini");
|
||||||
@@ -30,6 +36,7 @@ class ConfigCenter {
|
|||||||
int SetVideoFrameRate(VIDEO_FRAME_RATE video_frame_rate);
|
int SetVideoFrameRate(VIDEO_FRAME_RATE video_frame_rate);
|
||||||
int SetVideoEncodeFormat(VIDEO_ENCODE_FORMAT video_encode_format);
|
int SetVideoEncodeFormat(VIDEO_ENCODE_FORMAT video_encode_format);
|
||||||
int SetHardwareVideoCodec(bool hardware_video_codec);
|
int SetHardwareVideoCodec(bool hardware_video_codec);
|
||||||
|
int SetTurnMode(TURN_MODE turn_mode);
|
||||||
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& signal_server_host);
|
int SetServerHost(const std::string& signal_server_host);
|
||||||
@@ -49,6 +56,7 @@ class ConfigCenter {
|
|||||||
VIDEO_FRAME_RATE GetVideoFrameRate() const;
|
VIDEO_FRAME_RATE GetVideoFrameRate() const;
|
||||||
VIDEO_ENCODE_FORMAT GetVideoEncodeFormat() const;
|
VIDEO_ENCODE_FORMAT GetVideoEncodeFormat() const;
|
||||||
bool IsHardwareVideoCodec() const;
|
bool IsHardwareVideoCodec() const;
|
||||||
|
TURN_MODE GetTurnMode() const;
|
||||||
bool IsEnableTurn() const;
|
bool IsEnableTurn() const;
|
||||||
bool IsEnableSrtp() const;
|
bool IsEnableSrtp() const;
|
||||||
std::string GetSignalServerHost() const;
|
std::string GetSignalServerHost() const;
|
||||||
@@ -77,7 +85,7 @@ class ConfigCenter {
|
|||||||
VIDEO_FRAME_RATE video_frame_rate_ = VIDEO_FRAME_RATE::FPS_60;
|
VIDEO_FRAME_RATE video_frame_rate_ = VIDEO_FRAME_RATE::FPS_60;
|
||||||
VIDEO_ENCODE_FORMAT video_encode_format_ = VIDEO_ENCODE_FORMAT::H264;
|
VIDEO_ENCODE_FORMAT video_encode_format_ = VIDEO_ENCODE_FORMAT::H264;
|
||||||
bool hardware_video_codec_ = false;
|
bool hardware_video_codec_ = false;
|
||||||
bool enable_turn_ = true;
|
TURN_MODE turn_mode_ = TURN_MODE::AUTO_UDP_TCP;
|
||||||
bool enable_srtp_ = false;
|
bool enable_srtp_ = false;
|
||||||
std::string signal_server_host_ = "";
|
std::string signal_server_host_ = "";
|
||||||
std::string signal_server_host_default_ = "api.crossdesk.cn";
|
std::string signal_server_host_default_ = "api.crossdesk.cn";
|
||||||
|
|||||||
+2
-1
@@ -1151,7 +1151,8 @@ int Render::CreateConnectionPeer() {
|
|||||||
ConfigCenter::VIDEO_ENCODE_FORMAT::AV1
|
ConfigCenter::VIDEO_ENCODE_FORMAT::AV1
|
||||||
? true
|
? true
|
||||||
: false;
|
: false;
|
||||||
params_.enable_turn = config_center_->IsEnableTurn();
|
params_.turn_mode =
|
||||||
|
static_cast<TurnMode>(config_center_->GetTurnMode());
|
||||||
params_.enable_srtp = config_center_->IsEnableSrtp();
|
params_.enable_srtp = config_center_->IsEnableSrtp();
|
||||||
params_.video_quality =
|
params_.video_quality =
|
||||||
static_cast<VideoQuality>(config_center_->GetVideoQuality());
|
static_cast<VideoQuality>(config_center_->GetVideoQuality());
|
||||||
|
|||||||
+1
-1
Submodule submodules/minirtc updated: 9e5ce698df...658768547f
Reference in New Issue
Block a user