mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Merge 4.0release.
This commit is contained in:
commit
3da0b57121
9 changed files with 160 additions and 34 deletions
|
@ -58,6 +58,9 @@ const char* _srs_version = "XCORE-" RTMP_SIG_SRS_SERVER;
|
|||
// '\r'
|
||||
#define SRS_CR (char)SRS_CONSTS_CR
|
||||
|
||||
// Overwrite the config by env.
|
||||
#define SRS_OVERWRITE_BY_ENV_SECONDS(key) if (getenv(key)) return ::atoi(getenv(key)) * SRS_UTIME_SECONDS
|
||||
|
||||
/**
|
||||
* dumps the ingest/transcode-engine in @param dir to amf0 object @param engine.
|
||||
* @param dir the transcode or ingest config directive.
|
||||
|
@ -2385,11 +2388,11 @@ srs_error_t SrsConfig::check_normal_config()
|
|||
&& n != "max_connections" && n != "daemon" && n != "heartbeat"
|
||||
&& n != "http_api" && n != "stats" && n != "vhost" && n != "pithy_print_ms"
|
||||
&& n != "http_server" && n != "stream_caster" && n != "rtc_server" && n != "srt_server"
|
||||
&& n != "utc_time" && n != "work_dir" && n != "asprocess"
|
||||
&& n != "utc_time" && n != "work_dir" && n != "asprocess" && n != "server_id"
|
||||
&& n != "ff_log_level" && n != "grace_final_wait" && n != "force_grace_quit"
|
||||
&& n != "grace_start_wait" && n != "empty_ip_ok" && n != "disable_daemon_for_docker"
|
||||
&& n != "inotify_auto_reload" && n != "auto_reload_for_docker" && n != "tcmalloc_release_rate"
|
||||
&& n != "query_latest_version" && n != "threads"
|
||||
&& n != "query_latest_version" && n != "first_wait_for_qlv" && n != "threads"
|
||||
&& n != "circuit_breaker" && n != "is_full" && n != "in_docker"
|
||||
) {
|
||||
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal directive %s", n.c_str());
|
||||
|
@ -2929,6 +2932,90 @@ SrsConfDirective* SrsConfig::get_root()
|
|||
return root;
|
||||
}
|
||||
|
||||
string srs_server_id_path(string pid_file)
|
||||
{
|
||||
string path = srs_string_replace(pid_file, ".pid", ".id");
|
||||
if (!srs_string_ends_with(path, ".id")) {
|
||||
path += ".id";
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
string srs_try_read_file(string path) {
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
SrsFileReader r;
|
||||
if ((err = r.open(path)) != srs_success) {
|
||||
srs_freep(err);
|
||||
return "";
|
||||
}
|
||||
|
||||
static char buf[1024];
|
||||
ssize_t nn = 0;
|
||||
if ((err = r.read(buf, sizeof(buf), &nn)) != srs_success) {
|
||||
srs_freep(err);
|
||||
return "";
|
||||
}
|
||||
|
||||
if (nn > 0) {
|
||||
return string(buf, nn);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void srs_try_write_file(string path, string content) {
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
SrsFileWriter w;
|
||||
if ((err = w.open(path)) != srs_success) {
|
||||
srs_freep(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((err = w.write((void*)content.data(), content.length(), NULL)) != srs_success) {
|
||||
srs_freep(err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
string SrsConfig::get_server_id()
|
||||
{
|
||||
static string DEFAULT = "";
|
||||
|
||||
// Try to read DEFAULT from server id file.
|
||||
if (DEFAULT.empty()) {
|
||||
DEFAULT = srs_try_read_file(srs_server_id_path(get_pid_file()));
|
||||
}
|
||||
|
||||
// Generate a random one if empty.
|
||||
if (DEFAULT.empty()) {
|
||||
DEFAULT = srs_generate_stat_vid();
|
||||
}
|
||||
|
||||
// Get the server id from env, config or DEFAULT.
|
||||
string server_id;
|
||||
|
||||
if (getenv("SRS_SERVER_ID")) {
|
||||
server_id = getenv("SRS_SERVER_ID");
|
||||
}
|
||||
|
||||
SrsConfDirective* conf = root->get("server_id");
|
||||
if (conf) {
|
||||
server_id = conf->arg0();
|
||||
}
|
||||
|
||||
if (server_id.empty()) {
|
||||
server_id = DEFAULT;
|
||||
}
|
||||
|
||||
// Write server id to tmp file.
|
||||
if (!server_id.empty()) {
|
||||
srs_try_write_file(srs_server_id_path(get_pid_file()), server_id);
|
||||
}
|
||||
|
||||
return server_id;
|
||||
}
|
||||
|
||||
int SrsConfig::get_max_connections()
|
||||
{
|
||||
static int DEFAULT = 1000;
|
||||
|
@ -3029,6 +3116,20 @@ bool SrsConfig::whether_query_latest_version()
|
|||
return SRS_CONF_PERFER_TRUE(conf->arg0());
|
||||
}
|
||||
|
||||
srs_utime_t SrsConfig::first_wait_for_qlv()
|
||||
{
|
||||
SRS_OVERWRITE_BY_ENV_SECONDS("SRS_FIRST_WAIT_FOR_QLV");
|
||||
|
||||
static srs_utime_t DEFAULT = 5 * 60 * SRS_UTIME_SECONDS;
|
||||
|
||||
SrsConfDirective* conf = root->get("first_wait_for_qlv");
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
return ::atoi(conf->arg0().c_str()) * SRS_UTIME_SECONDS;
|
||||
}
|
||||
|
||||
bool SrsConfig::empty_ip_ok()
|
||||
{
|
||||
static bool DEFAULT = true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue