1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-15 04:42:04 +00:00

Config: Add utest for configuring with ENV variables. v5.0.100 (#3284)

* Config: Add utest for configuring with ENV variables.

Co-authored-by: pengfei.ma <pengfei.ma@ctechm.com>
Co-authored-by: winlin <winlin@vip.126.com>
This commit is contained in:
mapengfei53 2022-12-01 23:03:50 +08:00 committed by GitHub
parent a4d9e45545
commit c7b7921712
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 1073 additions and 74 deletions

View file

@ -914,6 +914,7 @@ vhost scope.vhost.srs.com {
# the default chunk size is 128, max is 65536,
# some client does not support chunk size change,
# vhost chunk size will override the global value.
# Overwrite by env SRS_VHOST_CHUNK_SIZE for all vhosts.
# default: global chunk size.
chunk_size 128;
@ -922,11 +923,13 @@ vhost scope.vhost.srs.com {
# but for some peer(encoder), it never send message but use a different ack size.
# We can chnage the default ack size in server-side, to send acknowledge message,
# or the encoder maybe blocked after publishing for some time.
# Overwrite by env SRS_VHOST_IN_ACK_SIZE for all vhosts.
# Default: 0
in_ack_size 0;
# The output ack size, 0 to not set.
# This is used to notify the peer(player) to send acknowledge to server.
# Overwrite by env SRS_VHOST_OUT_ACK_SIZE for all vhosts.
# Default: 2500000
out_ack_size 2500000;
}
@ -1099,6 +1102,7 @@ vhost play.srs.com {
# Limit the max frames in gop cache. It might cause OOM if video stream has no IDR frame, so we limit to N
# frames by default. Note that it's the size of gop cache, including videos, audios and other messages.
# Overwrite by env SRS_VHOST_PLAY_GOP_CACHE_MAX_FRAMES for all vhosts.
# default: 2500
gop_cache_max_frames 2500;
@ -1700,6 +1704,7 @@ vhost hls.srs.com {
hls_ts_ctx on;
# the hls fragment in seconds, the duration of a piece of ts.
# Overwrite by env SRS_VHOST_HLS_HLS_FRAGMENT for all vhosts.
# default: 10
hls_fragment 10;
# the hls m3u8 target duration ratio,
@ -1892,7 +1897,7 @@ vhost hds.srs.com {
# default: off
enabled on;
# the hds fragment in seconds.
# Overwrite by env SRS_VHOST_HDS_FRAGMENT for all vhosts.
# Overwrite by env SRS_VHOST_HDS_HDS_FRAGMENT for all vhosts.
# default: 10
hds_fragment 10;
# the hds window in seconds, erase the segment when exceed the window.

View file

@ -8,6 +8,7 @@ The changelog for SRS.
## SRS 5.0 Changelog
* v5.0, 2022-12-01, Config: Add utest for configuring with ENV variables. v5.0.100
* v5.0, 2022-12-01, Live: Fix bug for gop cache limits. v5.0.99
* v5.0, 2022-11-25, SRT: Support transform tlpkdrop to tlpktdrop. 5.0.98
* v5.0, 2022-11-25, Config: Add ENV tips for config. 5.0.97

View file

@ -2805,7 +2805,7 @@ bool SrsConfig::get_daemon()
bool SrsConfig::get_in_docker()
{
SRS_OVERWRITE_BY_ENV_BOOL("srs.in_docker");
SRS_OVERWRITE_BY_ENV_BOOL("srs.in_docker"); // SRS_IN_DOCKER
static bool DEFAULT = false;
@ -2897,7 +2897,7 @@ string SrsConfig::get_server_id()
// Get the server id from env, config or DEFAULT.
string server_id;
if (!srs_getenv("srs.server_id").empty()) {
if (!srs_getenv("srs.server_id").empty()) { // SRS_SERVER_ID
server_id = srs_getenv("srs.server_id");
} else {
SrsConfDirective* conf = root->get("server_id");
@ -2935,8 +2935,7 @@ vector<string> SrsConfig::get_listens()
std::vector<string> ports;
if (!srs_getenv("srs.listen").empty()) { // SRS_LISTEN
ports.push_back(srs_getenv("srs.listen"));
return ports;
return srs_string_split(srs_getenv("srs.listen"), " ");
}
SrsConfDirective* conf = root->get("listen");
@ -3311,7 +3310,7 @@ int SrsConfig::get_dying_threshold()
int SrsConfig::get_dying_pulse()
{
SRS_OVERWRITE_BY_ENV_INT("srs.circuit_breaker.dying_threshold"); // SRS_CIRCUIT_BREAKER_DYING_THRESHOLD
SRS_OVERWRITE_BY_ENV_INT("srs.circuit_breaker.dying_pulse"); // SRS_CIRCUIT_BREAKER_DYING_PULSE
static int DEFAULT = 5;
@ -4505,7 +4504,7 @@ srs_utime_t SrsConfig::get_rtc_pli_for_rtmp(string vhost)
static srs_utime_t DEFAULT = 6 * SRS_UTIME_SECONDS;
srs_utime_t v = 0;
if (!srs_getenv("srs.vhost.rtc.pli_for_rtmp").empty()) { // SRS_
if (!srs_getenv("srs.vhost.rtc.pli_for_rtmp").empty()) { // SRS_VHOST_RTC_PLI_FOR_RTMP
v = (srs_utime_t)(::atof(srs_getenv("srs.vhost.rtc.pli_for_rtmp").c_str()) * SRS_UTIME_SECONDS);
} else {
SrsConfDirective* conf = get_rtc(vhost);
@ -4769,8 +4768,8 @@ bool SrsConfig::get_atc_auto(string vhost)
int SrsConfig::get_time_jitter(string vhost)
{
if (!srs_getenv("srs.vhost.play.mw_latency").empty()) { // SRS_
return srs_time_jitter_string2int(srs_getenv("srs.vhost.play.mw_latency"));
if (!srs_getenv("srs.vhost.play.time_jitter").empty()) { // SRS_VHOST_PLAY_TIME_JITTER
return srs_time_jitter_string2int(srs_getenv("srs.vhost.play.time_jitter"));
}
static string DEFAULT = "full";
@ -4916,6 +4915,8 @@ SrsConfDirective* SrsConfig::get_refer_publish(string vhost)
int SrsConfig::get_in_ack_size(string vhost)
{
SRS_OVERWRITE_BY_ENV_INT("srs.vhost.in_ack_size"); // SRS_VHOST_IN_ACK_SIZE
static int DEFAULT = 0;
SrsConfDirective* conf = get_vhost(vhost);
@ -4933,6 +4934,8 @@ int SrsConfig::get_in_ack_size(string vhost)
int SrsConfig::get_out_ack_size(string vhost)
{
SRS_OVERWRITE_BY_ENV_INT("srs.vhost.out_ack_size"); // SRS_VHOST_OUT_ACK_SIZE
static int DEFAULT = 2500000;
SrsConfDirective* conf = get_vhost(vhost);
@ -4950,6 +4953,8 @@ int SrsConfig::get_out_ack_size(string vhost)
int SrsConfig::get_chunk_size(string vhost)
{
SRS_OVERWRITE_BY_ENV_INT("srs.vhost.chunk_size"); // SRS_VHOST_CHUNK_SIZE
if (vhost.empty()) {
return get_global_chunk_size();
}
@ -5069,7 +5074,7 @@ srs_utime_t SrsConfig::get_mr_sleep(string vhost)
srs_utime_t SrsConfig::get_mw_sleep(string vhost, bool is_rtc)
{
if (!srs_getenv("srs.vhost.play.mw_latency").empty()) { // SRS_
if (!srs_getenv("srs.vhost.play.mw_latency").empty()) { // SRS_VHOST_PLAY_MW_LATENCY
int v = ::atoi(srs_getenv("srs.vhost.play.mw_latency").c_str());
if (is_rtc && v > 0) {
srs_warn("For RTC, we ignore mw_latency");
@ -5110,7 +5115,7 @@ srs_utime_t SrsConfig::get_mw_sleep(string vhost, bool is_rtc)
int SrsConfig::get_mw_msgs(string vhost, bool is_realtime, bool is_rtc)
{
if (!srs_getenv("srs.vhost.play.mw_msgs").empty()) { // SRS_
if (!srs_getenv("srs.vhost.play.mw_msgs").empty()) { // SRS_VHOST_PLAY_MW_MSGS
int v = ::atoi(srs_getenv("srs.vhost.play.mw_msgs").c_str());
if (v > SRS_PERF_MW_MSGS) {
srs_warn("reset mw_msgs %d to max %d", v, SRS_PERF_MW_MSGS);
@ -5303,7 +5308,7 @@ srs_utime_t SrsConfig::get_publish_normal_timeout(string vhost)
int SrsConfig::get_global_chunk_size()
{
SRS_OVERWRITE_BY_ENV_INT("srs.chunk_size"); // SRS_CHUNK_SIZE
SRS_OVERWRITE_BY_ENV_INT("srs.vhost.chunk_size"); // SRS_VHOST_CHUNK_SIZE
SrsConfDirective* conf = root->get("chunk_size");
if (!conf || conf->arg0().empty()) {
@ -6639,6 +6644,8 @@ bool SrsConfig::get_hls_enabled(string vhost)
bool SrsConfig::get_hls_enabled(SrsConfDirective* vhost)
{
SRS_OVERWRITE_BY_ENV_BOOL("srs.vhost.hls.enabled"); // SRS_VHOST_HLS_ENABLED
static bool DEFAULT = false;
SrsConfDirective* conf = vhost->get("hls");
@ -6733,6 +6740,8 @@ string SrsConfig::get_hls_ts_file(string vhost)
bool SrsConfig::get_hls_ts_floor(string vhost)
{
SRS_OVERWRITE_BY_ENV_BOOL("srs.vhost.hls.hls_ts_floor"); // SRS_VHOST_HLS_HLS_TS_FLOOR
static bool DEFAULT = false;
SrsConfDirective* conf = get_hls(vhost);
@ -7239,6 +7248,8 @@ bool SrsConfig::get_dvr_enabled(string vhost)
bool SrsConfig::get_dvr_enabled(SrsConfDirective* vhost)
{
SRS_OVERWRITE_BY_ENV_BOOL("srs.vhost.dvr.enabled"); // SRS_VHOST_DVR_ENABLED
static bool DEFAULT = false;
SrsConfDirective* conf = vhost->get("dvr");
@ -7347,8 +7358,8 @@ bool SrsConfig::get_dvr_wait_keyframe(string vhost)
int SrsConfig::get_dvr_time_jitter(string vhost)
{
if (!srs_getenv("srs.vhost.dvr.dvr_wait_keyframe").empty()) { // SRS_
return srs_time_jitter_string2int(srs_getenv("srs.vhost.dvr.dvr_wait_keyframe"));
if (!srs_getenv("srs.vhost.dvr.time_jitter").empty()) { // SRS_VHOST_DVR_TIME_JITTER
return srs_time_jitter_string2int(srs_getenv("srs.vhost.dvr.time_jitter"));
}
static string DEFAULT = "full";
@ -8103,7 +8114,7 @@ string SrsConfig::get_https_stream_ssl_cert()
bool SrsConfig::get_vhost_http_enabled(string vhost)
{
SRS_OVERWRITE_BY_ENV_BOOL("srs.http_static.enabled"); // SRS_HTTP_STATIC_ENABLED
SRS_OVERWRITE_BY_ENV_BOOL("srs.vhost.http_static.enabled"); // SRS_VHOST_HTTP_STATIC_ENABLED
static bool DEFAULT = false;
@ -8127,7 +8138,7 @@ bool SrsConfig::get_vhost_http_enabled(string vhost)
string SrsConfig::get_vhost_http_mount(string vhost)
{
SRS_OVERWRITE_BY_ENV_STRING("srs.http_static.mount"); // SRS_HTTP_STATIC_MOUNT
SRS_OVERWRITE_BY_ENV_STRING("srs.vhost.http_static.mount"); // SRS_VHOST_HTTP_STATIC_MOUNT
static string DEFAULT = "[vhost]/";
@ -8151,7 +8162,7 @@ string SrsConfig::get_vhost_http_mount(string vhost)
string SrsConfig::get_vhost_http_dir(string vhost)
{
SRS_OVERWRITE_BY_ENV_STRING("srs.http_static.dir"); // SRS_HTTP_STATIC_DIR
SRS_OVERWRITE_BY_ENV_STRING("srs.vhost.http_static.dir"); // SRS_VHOST_HTTP_STATIC_DIR
static string DEFAULT = "./objs/nginx/html";
@ -8175,6 +8186,8 @@ string SrsConfig::get_vhost_http_dir(string vhost)
bool SrsConfig::get_vhost_http_remux_enabled(string vhost)
{
SRS_OVERWRITE_BY_ENV_BOOL("srs.vhost.http_remux.enabled"); // SRS_VHOST_HTTP_REMUX_ENABLED
static bool DEFAULT = false;
SrsConfDirective* conf = get_vhost(vhost);
@ -8187,7 +8200,7 @@ bool SrsConfig::get_vhost_http_remux_enabled(string vhost)
bool SrsConfig::get_vhost_http_remux_enabled(SrsConfDirective* vhost)
{
SRS_OVERWRITE_BY_ENV_BOOL("srs.http_remux.enabled"); // SRS_HTTP_REMUX_ENABLED
SRS_OVERWRITE_BY_ENV_BOOL("srs.vhost.http_remux.enabled"); // SRS_VHOST_HTTP_REMUX_ENABLED
static bool DEFAULT = false;
@ -8206,7 +8219,7 @@ bool SrsConfig::get_vhost_http_remux_enabled(SrsConfDirective* vhost)
srs_utime_t SrsConfig::get_vhost_http_remux_fast_cache(string vhost)
{
SRS_OVERWRITE_BY_ENV_FLOAT_SECONDS("srs.http_remux.fast_cache"); // SRS_HTTP_REMUX_FAST_CACHE
SRS_OVERWRITE_BY_ENV_FLOAT_SECONDS("srs.vhost.http_remux.fast_cache"); // SRS_VHOST_HTTP_REMUX_FAST_CACHE
static srs_utime_t DEFAULT = 0;
@ -8230,7 +8243,7 @@ srs_utime_t SrsConfig::get_vhost_http_remux_fast_cache(string vhost)
string SrsConfig::get_vhost_http_remux_mount(string vhost)
{
SRS_OVERWRITE_BY_ENV_STRING("srs.http_remux.mount"); // SRS_HTTP_REMUX_MOUNT
SRS_OVERWRITE_BY_ENV_STRING("srs.vhost.http_remux.mount"); // SRS_VHOST_HTTP_REMUX_MOUNT
static string DEFAULT = "[vhost]/[app]/[stream].flv";

View file

@ -9,6 +9,6 @@
#define VERSION_MAJOR 5
#define VERSION_MINOR 0
#define VERSION_REVISION 99
#define VERSION_REVISION 100
#endif

View file

@ -95,6 +95,52 @@ srs_error_t MockSrsConfig::build_buffer(std::string src, srs_internal::SrsConfig
return err;
}
int ISrsSetEnvConfig::srs_setenv(const std::string& key, const std::string& value, bool overwrite)
{
string ekey = key;
if (srs_string_starts_with(key, "$")) {
ekey = key.substr(1);
}
if (ekey.empty()) {
return -1;
}
std::string::iterator it;
for (it = ekey.begin(); it != ekey.end(); ++it) {
if (*it >= 'a' && *it <= 'z') {
*it += ('A' - 'a');
} else if (*it == '.') {
*it = '_';
}
}
return ::setenv(ekey.c_str(), value.c_str(), overwrite);
}
int ISrsSetEnvConfig::srs_unsetenv(const std::string& key)
{
string ekey = key;
if (srs_string_starts_with(key, "$")) {
ekey = key.substr(1);
}
if (ekey.empty()) {
return -1;
}
std::string::iterator it;
for (it = ekey.begin(); it != ekey.end(); ++it) {
if (*it >= 'a' && *it <= 'z') {
*it += ('A' - 'a');
} else if (*it == '.') {
*it = '_';
}
}
return ::unsetenv(ekey.c_str());
}
VOID TEST(ConfigTest, CheckMacros)
{
#ifndef SRS_CONSTS_LOCALHOST
@ -3889,3 +3935,915 @@ VOID TEST(ConfigMainTest, SrtServerTlpktDrop)
}
}
VOID TEST(ConfigEnvTest, CheckEnvValuesGlobal)
{
srs_error_t err;
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(pid, "SRS_PID", "xxx");
EXPECT_STREQ("xxx", conf.get_pid_file().c_str());
SrsSetEnvConfig(log_file, "SRS_SRS_LOG_FILE", "xxx2");
EXPECT_STREQ("xxx2", conf.get_log_file().c_str());
SrsSetEnvConfig(log_level, "SRS_SRS_LOG_LEVEL", "xxx3");
EXPECT_STREQ("xxx3", conf.get_log_level().c_str());
SrsSetEnvConfig(log_level_v2, "SRS_SRS_LOG_LEVEL_V2", "xxx4");
EXPECT_STREQ("xxx4", conf.get_log_level_v2().c_str());
SrsSetEnvConfig(work_dir, "SRS_WORK_DIR", "xxx5");
EXPECT_STREQ("xxx5", conf.get_work_dir().c_str());
}
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(ff_log_dir, "SRS_FF_LOG_DIR", "yyy");
EXPECT_STREQ("yyy", conf.get_ff_log_dir().c_str());
SrsSetEnvConfig(ff_log_level, "SRS_FF_LOG_LEVEL", "yyy2");
EXPECT_STREQ("yyy2", conf.get_ff_log_level().c_str());
}
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(max_connections, "SRS_MAX_CONNECTIONS", "1024");
EXPECT_EQ(1024, conf.get_max_connections());
SrsSetEnvConfig(utc_time, "SRS_UTC_TIME", "on");
EXPECT_TRUE(conf.get_utc_time());
SrsSetEnvConfig(pithy_print, "SRS_PITHY_PRINT_MS", "20000");
EXPECT_EQ(20 * SRS_UTIME_SECONDS, conf.get_pithy_print());
SrsSetEnvConfig(asprocess, "SRS_ASPROCESS", "on");
EXPECT_TRUE(conf.get_asprocess());
SrsSetEnvConfig(empty_ip_ok, "SRS_EMPTY_IP_OK", "off");
EXPECT_FALSE(conf.empty_ip_ok());
SrsSetEnvConfig(in_docker, "SRS_IN_DOCKER", "on");
EXPECT_TRUE(conf.get_in_docker());
}
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(grace_start_wait, "SRS_GRACE_START_WAIT", "2000");
EXPECT_EQ(2000 * SRS_UTIME_MILLISECONDS, conf.get_grace_start_wait());
SrsSetEnvConfig(grace_final_wait, "SRS_GRACE_FINAL_WAIT", "3000");
EXPECT_EQ(3000 * SRS_UTIME_MILLISECONDS, conf.get_grace_final_wait());
SrsSetEnvConfig(is_force_grace_quit, "SRS_FORCE_GRACE_QUIT", "on");
EXPECT_TRUE(conf.is_force_grace_quit());
SrsSetEnvConfig(disable_daemon_for_docker, "SRS_DISABLE_DAEMON_FOR_DOCKER", "off");
EXPECT_FALSE(conf.disable_daemon_for_docker());
}
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(inotify_auto_reload, "SRS_INOTIFY_AUTO_RELOAD", "on");
EXPECT_TRUE(conf.inotify_auto_reload());
SrsSetEnvConfig(auto_reload_for_docker, "SRS_AUTO_RELOAD_FOR_DOCKER", "off");
EXPECT_FALSE(conf.auto_reload_for_docker());
}
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(tcmalloc_release_rate, "SRS_TCMALLOC_RELEASE_RATE", "20");
EXPECT_EQ(10, conf.tcmalloc_release_rate());
SrsSetEnvConfig(tcmalloc_release_rate_low, "SRS_TCMALLOC_RELEASE_RATE", "5.2");
EXPECT_EQ(5.2, conf.tcmalloc_release_rate());
SrsSetEnvConfig(whether_query_latest_version, "SRS_QUERY_LATEST_VERSION", "off");
EXPECT_FALSE(conf.whether_query_latest_version());
SrsSetEnvConfig(first_wait_for_qlv, "SRS_FIRST_WAIT_FOR_QLV", "200");
EXPECT_EQ(200 * SRS_UTIME_SECONDS, conf.first_wait_for_qlv());
}
}
VOID TEST(ConfigEnvTest, CheckEnvValuesthreads)
{
srs_error_t err;
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(threads_interval, "SRS_THREADS_INTERVAL", "10");
EXPECT_EQ(10 * SRS_UTIME_SECONDS, conf.get_threads_interval());
}
}
VOID TEST(ConfigEnvTest, CheckEnvValuesRtmp)
{
srs_error_t err;
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(listens, "SRS_LISTEN", "1935");
vector<string> listens = conf.get_listens();
EXPECT_EQ(1, (int)listens.size());
EXPECT_STREQ("1935", listens.at(0).c_str());
}
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(listens, "SRS_LISTEN", "1935 1936");
vector<string> listens = conf.get_listens();
EXPECT_EQ(2, (int)listens.size());
EXPECT_STREQ("1935", listens.at(0).c_str());
EXPECT_STREQ("1936", listens.at(1).c_str());
}
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(listens, "SRS_LISTEN", "1935 1936 1937");
vector<string> listens = conf.get_listens();
EXPECT_EQ(3, (int)listens.size());
EXPECT_STREQ("1935", listens.at(0).c_str());
EXPECT_STREQ("1936", listens.at(1).c_str());
EXPECT_STREQ("1937", listens.at(2).c_str());
}
}
VOID TEST(ConfigEnvTest, CheckEnvValuesHttpApi)
{
srs_error_t err;
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(http_api_enabled, "SRS_HTTP_API_ENABLED", "on");
EXPECT_TRUE(conf.get_http_api_enabled());
SrsSetEnvConfig(http_api_listen, "SRS_HTTP_API_LISTEN", "xxx");
EXPECT_STREQ("xxx", conf.get_http_api_listen().c_str());
SrsSetEnvConfig(http_api_crossdomain, "SRS_HTTP_API_CROSSDOMAIN", "off");
EXPECT_FALSE(conf.get_http_api_crossdomain());
}
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(raw_api, "SRS_HTTP_API_RAW_API_ENABLED", "on");
EXPECT_TRUE(conf.get_raw_api());
SrsSetEnvConfig(raw_api_allow_reload, "SRS_HTTP_API_RAW_API_ALLOW_RELOAD", "on");
EXPECT_TRUE(conf.get_raw_api_allow_reload());
}
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(https_api_enabled, "SRS_HTTP_API_HTTPS_ENABLED", "on");
EXPECT_TRUE(conf.get_https_api_enabled());
SrsSetEnvConfig(https_api_listen, "SRS_HTTP_API_HTTPS_LISTEN", "xxx");
EXPECT_STREQ("xxx", conf.get_https_api_listen().c_str());
SrsSetEnvConfig(https_api_ssl_key, "SRS_HTTP_API_HTTPS_KEY", "xxx2");
EXPECT_STREQ("xxx2", conf.get_https_api_ssl_key().c_str());
SrsSetEnvConfig(https_api_ssl_cert, "SRS_HTTP_API_HTTPS_CERT", "xxx3");
EXPECT_STREQ("xxx3", conf.get_https_api_ssl_cert().c_str());
}
}
VOID TEST(ConfigEnvTest, CheckEnvValuesHttpServer)
{
srs_error_t err;
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(http_stream_enabled, "SRS_HTTP_SERVER_ENABLED", "on");
EXPECT_TRUE(conf.get_http_stream_enabled());
SrsSetEnvConfig(http_stream_listen, "SRS_HTTP_SERVER_LISTEN", "xxx");
EXPECT_STREQ("xxx", conf.get_http_stream_listen().c_str());
SrsSetEnvConfig(http_stream_dir, "SRS_HTTP_SERVER_DIR", "xxx2");
EXPECT_STREQ("xxx2", conf.get_http_stream_dir().c_str());
SrsSetEnvConfig(http_stream_crossdomain, "SRS_HTTP_SERVER_CROSSDOMAIN", "off");
EXPECT_FALSE(conf.get_http_stream_crossdomain());
}
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(https_stream_enabled, "SRS_HTTP_SERVER_HTTPS_ENABLED", "on");
EXPECT_TRUE(conf.get_https_stream_enabled());
SrsSetEnvConfig(https_stream_listen, "SRS_HTTP_SERVER_HTTPS_LISTEN", "xxx");
EXPECT_STREQ("xxx", conf.get_https_stream_listen().c_str());
SrsSetEnvConfig(https_stream_ssl_key, "SRS_HTTP_SERVER_HTTPS_KEY", "xxx2");
EXPECT_STREQ("xxx2", conf.get_https_stream_ssl_key().c_str());
SrsSetEnvConfig(https_stream_ssl_cert, "SRS_HTTP_SERVER_HTTPS_CERT", "xxx3");
EXPECT_STREQ("xxx3", conf.get_https_stream_ssl_cert().c_str());
}
}
VOID TEST(ConfigEnvTest, CheckEnvValuesSrtServer)
{
srs_error_t err;
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(srt_enabled, "SRS_SRT_SERVER_ENABLED", "on");
EXPECT_TRUE(conf.get_srt_enabled());
SrsSetEnvConfig(srt_listen_port, "SRS_SRT_SERVER_LISTEN", "10000");
EXPECT_EQ(10000, conf.get_srt_listen_port());
SrsSetEnvConfig(srto_maxbw, "SRS_SRT_SERVER_MAXBW", "1000000000");
EXPECT_EQ(1000000000, conf.get_srto_maxbw());
SrsSetEnvConfig(srto_mss, "SRS_SRT_SERVER_MMS", "1000");
EXPECT_EQ(1000, conf.get_srto_mss());
SrsSetEnvConfig(srto_conntimeout, "SRS_SRT_SERVER_CONNECT_TIMEOUT", "2000");
EXPECT_EQ(2000 * SRS_UTIME_MILLISECONDS, conf.get_srto_conntimeout());
SrsSetEnvConfig(srto_peeridletimeout, "SRS_SRT_SERVER_PEER_IDLE_TIMEOUT", "2000");
EXPECT_EQ(2000 * SRS_UTIME_MILLISECONDS, conf.get_srto_peeridletimeout());
SrsSetEnvConfig(default_app_name, "SRS_SRT_SERVER_DEFAULT_APP", "xxx");
EXPECT_STREQ("xxx", conf.get_default_app_name().c_str());
SrsSetEnvConfig(srto_peer_latency, "SRS_SRT_SERVER_PEERLATENCY", "1");
EXPECT_EQ(1, conf.get_srto_peer_latency());
SrsSetEnvConfig(srto_recv_latency, "SRS_SRT_SERVER_RECVLATENCY", "100");
EXPECT_EQ(100, conf.get_srto_recv_latency());
SrsSetEnvConfig(srto_latency, "SRS_SRT_SERVER_LATENCY", "100");
EXPECT_EQ(100, conf.get_srto_latency());
SrsSetEnvConfig(srto_tsbpdmode, "SRS_SRT_SERVER_TSBPDMODE", "off");
EXPECT_FALSE(conf.get_srto_tsbpdmode());
SrsSetEnvConfig(srto_tlpktdrop, "SRS_SRT_SERVER_TLPKTDROP", "off");
EXPECT_FALSE(conf.get_srto_tlpktdrop());
SrsSetEnvConfig(srto_sendbuf, "SRS_SRT_SERVER_SENDBUF", "2100000");
EXPECT_EQ(2100000, conf.get_srto_sendbuf());
SrsSetEnvConfig(srto_recvbuf, "SRS_SRT_SERVER_RECVBUF", "2100000");
EXPECT_EQ(2100000, conf.get_srto_recvbuf());
SrsSetEnvConfig(srto_passphrase, "SRS_SRT_SERVER_PASSPHRASE", "xxx2");
EXPECT_STREQ("xxx2", conf.get_srto_passphrase().c_str());
SrsSetEnvConfig(srto_pbkeylen, "SRS_SRT_SERVER_PBKEYLEN", "16");
EXPECT_EQ(16, conf.get_srto_pbkeylen());
}
}
VOID TEST(ConfigEnvTest, CheckEnvValuesVhostSrt)
{
srs_error_t err;
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(srt_enabled, "SRS_VHOST_SRT_ENABLED", "on");
EXPECT_TRUE(conf.get_srt_enabled("__defaultVhost__"));
SrsSetEnvConfig(srt_to_rtmp, "SRS_VHOST_SRT_SRT_TO_RTMP", "off");
EXPECT_FALSE(conf.get_srt_to_rtmp("__defaultVhost__"));
}
}
VOID TEST(ConfigEnvTest, CheckEnvValuesRtcServer)
{
srs_error_t err;
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(rtc_server_enabled, "SRS_RTC_SERVER_ENABLED", "on");
EXPECT_TRUE(conf.get_rtc_server_enabled());
SrsSetEnvConfig(rtc_server_listen, "SRS_RTC_SERVER_LISTEN", "8080");
EXPECT_EQ(8080, conf.get_rtc_server_listen());
SrsSetEnvConfig(rtc_server_protocol, "SRS_RTC_SERVER_PROTOCOL", "xxx");
EXPECT_STREQ("xxx", conf.get_rtc_server_protocol().c_str());
SrsSetEnvConfig(rtc_server_candidates, "SRS_RTC_SERVER_CANDIDATE", "192.168.0.1");
EXPECT_STREQ("192.168.0.1", conf.get_rtc_server_candidates().c_str());
SrsSetEnvConfig(use_auto_detect_network_ip, "SRS_RTC_SERVER_USE_AUTO_DETECT_NETWORK_IP", "off");
EXPECT_FALSE(conf.get_use_auto_detect_network_ip());
SrsSetEnvConfig(rtc_server_ip_family, "SRS_RTC_SERVER_IP_FAMILY", "xxx2");
EXPECT_STREQ("xxx2", conf.get_rtc_server_ip_family().c_str());
SrsSetEnvConfig(api_as_candidates, "SRS_RTC_SERVER_API_AS_CANDIDATES", "off");
EXPECT_FALSE(conf.get_api_as_candidates());
SrsSetEnvConfig(resolve_api_domain, "SRS_RTC_SERVER_RESOLVE_API_DOMAIN", "off");
EXPECT_FALSE(conf.get_resolve_api_domain());
SrsSetEnvConfig(keep_api_domain, "SRS_RTC_SERVER_KEEP_API_DOMAIN", "on");
EXPECT_TRUE(conf.get_keep_api_domain());
SrsSetEnvConfig(rtc_server_ecdsa, "SRS_RTC_SERVER_ECDSA", "off");
EXPECT_FALSE(conf.get_rtc_server_ecdsa());
SrsSetEnvConfig(rtc_server_encrypt, "SRS_RTC_SERVER_ENCRYPT", "off");
EXPECT_FALSE(conf.get_rtc_server_encrypt());
SrsSetEnvConfig(rtc_server_reuseport, "SRS_RTC_SERVER_REUSEPORT", "0");
EXPECT_EQ(0, conf.get_rtc_server_reuseport2());
SrsSetEnvConfig(rtc_server_merge_nalus, "SRS_RTC_SERVER_MERGE_NALUS", "on");
EXPECT_TRUE(conf.get_rtc_server_merge_nalus());
}
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(rtc_server_tcp_enabled, "SRS_RTC_SERVER_TCP_ENABLED", "on");
EXPECT_TRUE(conf.get_rtc_server_tcp_enabled());
SrsSetEnvConfig(get_rtc_server_tcp_listen, "SRS_RTC_SERVER_TCP_LISTEN", "8080");
EXPECT_EQ(8080, conf.get_rtc_server_tcp_listen());
}
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(rtc_server_black_hole, "SRS_RTC_SERVER_BLACK_HOLE_ENABLED", "on");
EXPECT_TRUE(conf.get_rtc_server_black_hole());
SrsSetEnvConfig(rtc_server_black_hole_addr, "SRS_RTC_SERVER_BLACK_HOLE_ADDR", "xxx");
EXPECT_STREQ("xxx", conf.get_rtc_server_black_hole_addr().c_str());
}
}
VOID TEST(ConfigEnvTest, CheckEnvValuesVhostRtc)
{
srs_error_t err;
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(rtc_enabled, "SRS_VHOST_RTC_ENABLED", "on");
EXPECT_TRUE(conf.get_rtc_enabled("__defaultVhost__"));
SrsSetEnvConfig(rtc_nack_enabled, "SRS_VHOST_RTC_NACK", "off");
EXPECT_FALSE(conf.get_rtc_nack_enabled("__defaultVhost__"));
SrsSetEnvConfig(rtc_nack_no_copy, "SRS_VHOST_RTC_NACK_NO_COPY", "off");
EXPECT_FALSE(conf.get_rtc_nack_no_copy("__defaultVhost__"));
SrsSetEnvConfig(rtc_twcc_enabled, "SRS_VHOST_RTC_TWCC", "off");
EXPECT_FALSE(conf.get_rtc_twcc_enabled("__defaultVhost__"));
SrsSetEnvConfig(rtc_stun_timeout, "SRS_VHOST_RTC_STUN_TIMEOUT", "15");
EXPECT_EQ(15 * SRS_UTIME_SECONDS, conf.get_rtc_stun_timeout("__defaultVhost__"));
SrsSetEnvConfig(rtc_stun_strict_check, "SRS_VHOST_RTC_STUN_STRICT_CHECK", "on");
EXPECT_TRUE(conf.get_rtc_stun_strict_check("__defaultVhost__"));
SrsSetEnvConfig(rtc_dtls_role, "SRS_VHOST_RTC_DTLS_ROLE", "xxx");
EXPECT_STREQ("xxx", conf.get_rtc_dtls_role("__defaultVhost__").c_str());
SrsSetEnvConfig(rtc_dtls_version, "SRS_VHOST_RTC_DTLS_VERSION", "xxx2");
EXPECT_STREQ("xxx2", conf.get_rtc_dtls_version("__defaultVhost__").c_str());
SrsSetEnvConfig(rtc_drop_for_pt, "SRS_VHOST_RTC_DROP_FOR_PT", "1");
EXPECT_EQ(1, conf.get_rtc_drop_for_pt("__defaultVhost__"));
SrsSetEnvConfig(rtc_from_rtmp, "SRS_VHOST_RTC_RTMP_TO_RTC", "on");
EXPECT_TRUE(conf.get_rtc_from_rtmp("__defaultVhost__"));
SrsSetEnvConfig(rtc_to_rtmp, "SRS_VHOST_RTC_RTC_TO_RTMP", "on");
EXPECT_TRUE(conf.get_rtc_to_rtmp("__defaultVhost__"));
SrsSetEnvConfig(rtc_keep_bframe, "SRS_VHOST_RTC_KEEP_BFRAME", "on");
EXPECT_TRUE(conf.get_rtc_keep_bframe("__defaultVhost__"));
}
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(rtc_pli_for_rtmp, "SRS_VHOST_RTC_PLI_FOR_RTMP", "15");
EXPECT_EQ(15 * SRS_UTIME_SECONDS, conf.get_rtc_pli_for_rtmp("__defaultVhost__"));
}
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(rtc_pli_for_rtmp, "SRS_VHOST_RTC_PLI_FOR_RTMP", "60");
EXPECT_EQ(6 * SRS_UTIME_SECONDS, conf.get_rtc_pli_for_rtmp("__defaultVhost__"));
}
}
VOID TEST(ConfigEnvTest, CheckEnvValuesVhostPlay)
{
srs_error_t err;
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(mw_msgs, "SRS_VHOST_PLAY_MW_MSGS", "64");
EXPECT_EQ(64, conf.get_mw_msgs("__defaultVhost__", true, true));
}
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(mw_msgs, "SRS_VHOST_PLAY_MW_MSGS", "256");
EXPECT_EQ(128, conf.get_mw_msgs("__defaultVhost__", true, true));
}
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(mw_sleep, "SRS_VHOST_PLAY_MW_LATENCY", "300");
EXPECT_EQ(0, conf.get_mw_sleep("__defaultVhost__", true));
}
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(mw_sleep, "SRS_VHOST_PLAY_MW_LATENCY", "300");
EXPECT_EQ(300 * SRS_UTIME_MILLISECONDS, conf.get_mw_sleep("__defaultVhost__", false));
}
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(time_jitter, "SRS_VHOST_PLAY_TIME_JITTER", "full");
EXPECT_EQ(0x1, conf.get_time_jitter("__defaultVhost__"));
SrsSetEnvConfig(time_jitter_zero, "SRS_VHOST_PLAY_TIME_JITTER", "zero");
EXPECT_EQ(0x2, conf.get_time_jitter("__defaultVhost__"));
}
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(gop_cache, "SRS_VHOST_PLAY_GOP_CACHE", "off");
EXPECT_FALSE(conf.get_gop_cache("__defaultVhost__"));
SrsSetEnvConfig(gop_cache_max_frames, "SRS_VHOST_PLAY_GOP_CACHE_MAX_FRAMES", "2000");
EXPECT_EQ(2000, conf.get_gop_cache_max_frames("__defaultVhost__"));
SrsSetEnvConfig(queue_length, "SRS_VHOST_PLAY_QUEUE_LENGTH", "20");
EXPECT_EQ(20 * SRS_UTIME_SECONDS, conf.get_queue_length("__defaultVhost__"));
SrsSetEnvConfig(atc, "SRS_VHOST_PLAY_ATC", "on");
EXPECT_TRUE(conf.get_atc("__defaultVhost__"));
SrsSetEnvConfig(mix_correct, "SRS_VHOST_PLAY_MIX_CORRECT", "on");
EXPECT_TRUE(conf.get_mix_correct("__defaultVhost__"));
SrsSetEnvConfig(atc_auto, "SRS_VHOST_PLAY_ATC_AUTO", "on");
EXPECT_TRUE(conf.get_atc_auto("__defaultVhost__"));
SrsSetEnvConfig(send_min_interval, "SRS_VHOST_PLAY_SEND_MIN_INTERVAL", "10");
EXPECT_EQ(10 * SRS_UTIME_MILLISECONDS, conf.get_send_min_interval("__defaultVhost__"));
SrsSetEnvConfig(reduce_sequence_header, "SRS_VHOST_PLAY_REDUCE_SEQUENCE_HEADER", "on");
EXPECT_TRUE(conf.get_reduce_sequence_header("__defaultVhost__"));
}
}
VOID TEST(ConfigEnvTest, CheckEnvValuesVhostPublish)
{
srs_error_t err;
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(mr_enabled, "SRS_VHOST_PUBLISH_MR", "on");
EXPECT_TRUE(conf.get_mr_enabled("__defaultVhost__"));
SrsSetEnvConfig(mr_sleep, "SRS_VHOST_PUBLISH_MR_LATENCY", "10");
EXPECT_EQ(10 * SRS_UTIME_MILLISECONDS, conf.get_mr_sleep("__defaultVhost__"));
SrsSetEnvConfig(publish_normal_timeout, "SRS_VHOST_PUBLISH_NORMAL_TIMEOUT", "10");
EXPECT_EQ(10 * SRS_UTIME_MILLISECONDS, conf.get_publish_normal_timeout("__defaultVhost__"));
SrsSetEnvConfig(publish_1stpkt_timeout, "SRS_VHOST_PUBLISH_FIRSTPKT_TIMEOUT", "30");
EXPECT_EQ(30 * SRS_UTIME_MILLISECONDS, conf.get_publish_1stpkt_timeout("__defaultVhost__"));
SrsSetEnvConfig(parse_sps, "SRS_VHOST_PUBLISH_PARSE_SPS", "off");
EXPECT_FALSE(conf.get_parse_sps("__defaultVhost__"));
SrsSetEnvConfig(try_annexb_first, "SRS_VHOST_PUBLISH_TRY_ANNEXB_FIRST", "off");
EXPECT_FALSE(conf.try_annexb_first("__defaultVhost__"));
}
}
VOID TEST(ConfigEnvTest, CheckEnvValuesCircuitBreaker)
{
srs_error_t err;
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(circuit_breaker, "SRS_CIRCUIT_BREAKER_ENABLED", "off");
EXPECT_FALSE(conf.get_circuit_breaker());
SrsSetEnvConfig(high_threshold, "SRS_CIRCUIT_BREAKER_HIGH_THRESHOLD", "60");
EXPECT_EQ(60, conf.get_high_threshold());
SrsSetEnvConfig(high_pulse, "SRS_CIRCUIT_BREAKER_HIGH_PULSE", "3");
EXPECT_EQ(3, conf.get_high_pulse());
SrsSetEnvConfig(critical_threshold, "SRS_CIRCUIT_BREAKER_CRITICAL_THRESHOLD", "100");
EXPECT_EQ(100, conf.get_critical_threshold());
SrsSetEnvConfig(critical_pulse, "SRS_CIRCUIT_BREAKER_CRITICAL_PULSE", "2");
EXPECT_EQ(2, conf.get_critical_pulse());
SrsSetEnvConfig(dying_threshold, "SRS_CIRCUIT_BREAKER_DYING_THRESHOLD", "88");
EXPECT_EQ(88, conf.get_dying_threshold());
SrsSetEnvConfig(dying_pulse, "SRS_CIRCUIT_BREAKER_DYING_PULSE", "2");
EXPECT_EQ(2, conf.get_dying_pulse());
}
}
VOID TEST(ConfigEnvTest, CheckEnvValuesTencentcloudCls)
{
srs_error_t err;
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(tencentcloud_cls_enabled, "SRS_TENCENTCLOUD_CLS_ENABLED", "on");
EXPECT_TRUE(conf.get_tencentcloud_cls_enabled());
SrsSetEnvConfig(tencentcloud_cls_label, "SRS_TENCENTCLOUD_CLS_LABEL", "xxx");
EXPECT_STREQ("xxx", conf.get_tencentcloud_cls_label().c_str());
SrsSetEnvConfig(tencentcloud_cls_tag, "SRS_TENCENTCLOUD_CLS_TAG", "xxx2");
EXPECT_STREQ("xxx2", conf.get_tencentcloud_cls_tag().c_str());
SrsSetEnvConfig(tencentcloud_cls_secret_id, "SRS_TENCENTCLOUD_CLS_SECRET_ID", "xxx3");
EXPECT_STREQ("xxx3", conf.get_tencentcloud_cls_secret_id().c_str());
SrsSetEnvConfig(tencentcloud_cls_secret_key, "SRS_TENCENTCLOUD_CLS_SECRET_KEY", "xxx4");
EXPECT_STREQ("xxx4", conf.get_tencentcloud_cls_secret_key().c_str());
SrsSetEnvConfig(tencentcloud_cls_endpoint, "SRS_TENCENTCLOUD_CLS_ENDPOINT", "yyy");
EXPECT_STREQ("yyy", conf.get_tencentcloud_cls_endpoint().c_str());
SrsSetEnvConfig(tencentcloud_cls_topic_id, "SRS_TENCENTCLOUD_CLS_TOPIC_ID", "yyy2");
EXPECT_STREQ("yyy2", conf.get_tencentcloud_cls_topic_id().c_str());
}
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(tencentcloud_cls_debug_logging, "SRS_TENCENTCLOUD_CLS_DEBUG_LOGGING", "on");
EXPECT_TRUE(conf.get_tencentcloud_cls_debug_logging());
SrsSetEnvConfig(tencentcloud_cls_stat_heartbeat, "SRS_TENCENTCLOUD_CLS_STAT_HEARTBEAT", "off");
EXPECT_FALSE(conf.get_tencentcloud_cls_stat_heartbeat());
SrsSetEnvConfig(tencentcloud_cls_heartbeat_ratio, "SRS_TENCENTCLOUD_CLS_HEARTBEAT_RATIO", "2");
EXPECT_EQ(2, conf.get_tencentcloud_cls_heartbeat_ratio());
SrsSetEnvConfig(tencentcloud_cls_stat_streams, "SRS_TENCENTCLOUD_CLS_STAT_STREAMS", "off");
EXPECT_FALSE(conf.get_tencentcloud_cls_stat_streams());
SrsSetEnvConfig(tencentcloud_cls_streams_ratio, "SRS_TENCENTCLOUD_CLS_STREAMS_RATIO", "2");
EXPECT_EQ(2, conf.get_tencentcloud_cls_streams_ratio());
}
}
VOID TEST(ConfigEnvTest, CheckEnvValuesTencentcloudApm)
{
srs_error_t err;
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(tencentcloud_apm_enabled, "SRS_TENCENTCLOUD_APM_ENABLED", "on");
EXPECT_TRUE(conf.get_tencentcloud_apm_enabled());
SrsSetEnvConfig(tencentcloud_apm_team, "SRS_TENCENTCLOUD_APM_TEAM", "xxx");
EXPECT_STREQ("xxx", conf.get_tencentcloud_apm_team().c_str());
SrsSetEnvConfig(tencentcloud_apm_token, "SRS_TENCENTCLOUD_APM_TOKEN", "xxx2");
EXPECT_STREQ("xxx2", conf.get_tencentcloud_apm_token().c_str());
SrsSetEnvConfig(tencentcloud_apm_endpoint, "SRS_TENCENTCLOUD_APM_ENDPOINT", "xxx3");
EXPECT_STREQ("xxx3", conf.get_tencentcloud_apm_endpoint().c_str());
SrsSetEnvConfig(tencentcloud_apm_service_name, "SRS_TENCENTCLOUD_APM_SERVICE_NAME", "srs");
EXPECT_STREQ("srs", conf.get_tencentcloud_apm_service_name().c_str());
SrsSetEnvConfig(tencentcloud_apm_debug_logging, "SRS_TENCENTCLOUD_APM_DEBUG_LOGGING", "on");
EXPECT_TRUE(conf.get_tencentcloud_apm_debug_logging());
}
}
VOID TEST(ConfigEnvTest, CheckEnvValuesExporter)
{
srs_error_t err;
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(exporter_enabled, "SRS_EXPORTER_ENABLED", "on");
EXPECT_TRUE(conf.get_exporter_enabled());
SrsSetEnvConfig(exporter_listen, "SRS_EXPORTER_LISTEN", "xxx");
EXPECT_STREQ("xxx", conf.get_exporter_listen().c_str());
SrsSetEnvConfig(exporter_label, "SRS_EXPORTER_LABEL", "xxx2");
EXPECT_STREQ("xxx2", conf.get_exporter_label().c_str());
SrsSetEnvConfig(exporter_tag, "SRS_EXPORTER_TAG", "xxx3");
EXPECT_STREQ("xxx3", conf.get_exporter_tag().c_str());
}
}
VOID TEST(ConfigEnvTest, CheckEnvValuesHeartbeat)
{
srs_error_t err;
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(heartbeat_enabled, "SRS_HEARTBEAT_ENABLED", "on");
EXPECT_TRUE(conf.get_heartbeat_enabled());
SrsSetEnvConfig(heartbeat_interval, "SRS_HEARTBEAT_INTERVAL", "5");
EXPECT_EQ(5 * SRS_UTIME_SECONDS, conf.get_heartbeat_interval());
SrsSetEnvConfig(heartbeat_url, "SRS_HEARTBEAT_URL", "xxx");
EXPECT_STREQ("xxx", conf.get_heartbeat_url().c_str());
SrsSetEnvConfig(heartbeat_device_id, "SRS_HEARTBEAT_DEVICE_ID", "xxx2");
EXPECT_STREQ("xxx2", conf.get_heartbeat_device_id().c_str());
SrsSetEnvConfig(heartbeat_summaries, "SRS_HEARTBEAT_SUMMARIES", "on");
EXPECT_TRUE(conf.get_heartbeat_summaries());
}
}
VOID TEST(ConfigEnvTest, CheckEnvValuesScope)
{
srs_error_t err;
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(realtime_enabled, "SRS_VHOST_MIN_LATENCY", "off");
EXPECT_FALSE(conf.get_realtime_enabled("__defaultVhost__", true));
}
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(realtime_enabled, "SRS_VHOST_MIN_LATENCY", "on");
EXPECT_TRUE(conf.get_realtime_enabled("__defaultVhost__", false));
}
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(tcp_nodelay, "SRS_VHOST_TCP_NODELAY", "on");
EXPECT_TRUE(conf.get_tcp_nodelay("__defaultVhost__"));
SrsSetEnvConfig(out_ack_size, "SRS_VHOST_OUT_ACK_SIZE", "2000000");
EXPECT_EQ(2000000, conf.get_out_ack_size("__defaultVhost__"));
SrsSetEnvConfig(in_ack_size, "SRS_VHOST_IN_ACK_SIZE", "1000");
EXPECT_EQ(1000, conf.get_in_ack_size("__defaultVhost__"));
SrsSetEnvConfig(chunk_size, "SRS_VHOST_CHUNK_SIZE", "50000");
EXPECT_EQ(50000, conf.get_chunk_size("__defaultVhost__"));
}
}
VOID TEST(ConfigEnvTest, CheckEnvValuesHttpStatic)
{
srs_error_t err;
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(http_enabled, "SRS_VHOST_HTTP_STATIC_ENABLED", "on");
EXPECT_TRUE(conf.get_vhost_http_enabled("__defaultVhost__"));
SrsSetEnvConfig(http_mount, "SRS_VHOST_HTTP_STATIC_MOUNT", "xxx");
EXPECT_STREQ("xxx", conf.get_vhost_http_mount("__defaultVhost__").c_str());
SrsSetEnvConfig(http_dir, "SRS_VHOST_HTTP_STATIC_DIR", "xxx2");
EXPECT_STREQ("xxx2", conf.get_vhost_http_dir("__defaultVhost__").c_str());
}
}
VOID TEST(ConfigEnvTest, CheckEnvValuesHttpRemux)
{
srs_error_t err;
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(http_remux_enabled, "SRS_VHOST_HTTP_REMUX_ENABLED", "on");
EXPECT_TRUE(conf.get_vhost_http_remux_enabled("__defaultVhost__"));
SrsSetEnvConfig(http_remux_fast_cache, "SRS_VHOST_HTTP_REMUX_FAST_CACHE", "5");
EXPECT_EQ(5 * SRS_UTIME_SECONDS, conf.get_vhost_http_remux_fast_cache("__defaultVhost__"));
SrsSetEnvConfig(http_remux_mount, "SRS_VHOST_HTTP_REMUX_MOUNT", "xxx");
EXPECT_STREQ("xxx", conf.get_vhost_http_remux_mount("__defaultVhost__").c_str());
}
}
VOID TEST(ConfigEnvTest, CheckEnvValuesDash)
{
srs_error_t err;
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(dash_enabled, "SRS_VHOST_DASH_ENABLED", "on");
EXPECT_TRUE(conf.get_dash_enabled("__defaultVhost__"));
SrsSetEnvConfig(dash_fragment, "SRS_VHOST_DASH_DASH_FRAGMENT", "30");
EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_dash_fragment("__defaultVhost__"));
SrsSetEnvConfig(dash_update_period, "SRS_VHOST_DASH_DASH_UPDATE_PERIOD", "10");
EXPECT_EQ(10 * SRS_UTIME_SECONDS, conf.get_dash_update_period("__defaultVhost__"));
SrsSetEnvConfig(dash_timeshift, "SRS_VHOST_DASH_DASH_TIMESHIFT", "100");
EXPECT_EQ(100 * SRS_UTIME_SECONDS, conf.get_dash_timeshift("__defaultVhost__"));
SrsSetEnvConfig(dash_path, "SRS_VHOST_DASH_DASH_PATH", "xxx");
EXPECT_STREQ("xxx", conf.get_dash_path("__defaultVhost__").c_str());
SrsSetEnvConfig(dash_mpd_file, "SRS_VHOST_DASH_DASH_MPD_FILE", "xxx2");
EXPECT_STREQ("xxx2", conf.get_dash_mpd_file("__defaultVhost__").c_str());
}
}
VOID TEST(ConfigEnvTest, CheckEnvValuesHds)
{
srs_error_t err;
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(hds_enabled, "SRS_VHOST_HDS_ENABLED", "on");
EXPECT_TRUE(conf.get_hds_enabled("__defaultVhost__"));
SrsSetEnvConfig(hds_fragment, "SRS_VHOST_HDS_HDS_FRAGMENT", "20");
EXPECT_EQ(20 * SRS_UTIME_SECONDS, conf.get_hds_fragment("__defaultVhost__"));
SrsSetEnvConfig(hds_fragment_float, "SRS_VHOST_HDS_HDS_FRAGMENT", "20.1");
EXPECT_EQ(20.1 * SRS_UTIME_SECONDS, conf.get_hds_fragment("__defaultVhost__"));
SrsSetEnvConfig(hds_window, "SRS_VHOST_HDS_HDS_WINDOW", "30");
EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_hds_window("__defaultVhost__"));
SrsSetEnvConfig(hds_window_float, "SRS_VHOST_HDS_HDS_WINDOW", "30.1");
EXPECT_EQ(30.1 * SRS_UTIME_SECONDS, conf.get_hds_window("__defaultVhost__"));
SrsSetEnvConfig(hds_path, "SRS_VHOST_HDS_HDS_PATH", "xxx");
EXPECT_STREQ("xxx", conf.get_hds_path("__defaultVhost__").c_str());
}
}
VOID TEST(ConfigEnvTest, CheckEnvValuesDvr)
{
srs_error_t err;
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(dvr_enabled, "SRS_VHOST_DVR_ENABLED", "on");
EXPECT_TRUE(conf.get_dvr_enabled("__defaultVhost__"));
SrsSetEnvConfig(dvr_plan, "SRS_VHOST_DVR_DVR_PLAN", "xxx");
EXPECT_STREQ("xxx", conf.get_dvr_plan("__defaultVhost__").c_str());
SrsSetEnvConfig(dvr_path, "SRS_VHOST_DVR_DVR_PATH", "xxx2");
EXPECT_STREQ("xxx2", conf.get_dvr_path("__defaultVhost__").c_str());
SrsSetEnvConfig(dvr_duration, "SRS_VHOST_DVR_DVR_DURATION", "60");
EXPECT_EQ(60 * SRS_UTIME_SECONDS, conf.get_dvr_duration("__defaultVhost__"));
SrsSetEnvConfig(dvr_wait_keyframe, "SRS_VHOST_DVR_DVR_WAIT_KEYFRAME", "off");
EXPECT_FALSE(conf.get_dvr_wait_keyframe("__defaultVhost__"));
SrsSetEnvConfig(dvr_time_jitter_full, "SRS_VHOST_DVR_TIME_JITTER", "full");
EXPECT_EQ(0x1, conf.get_dvr_time_jitter("__defaultVhost__"));
SrsSetEnvConfig(dvr_time_jitter_zero, "SRS_VHOST_DVR_TIME_JITTER", "zero");
EXPECT_EQ(0x2, conf.get_dvr_time_jitter("__defaultVhost__"));
}
}
VOID TEST(ConfigEnvTest, CheckEnvValuesHls)
{
srs_error_t err;
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(hls_enabled, "SRS_VHOST_HLS_ENABLED", "on");
EXPECT_TRUE(conf.get_hls_enabled("__defaultVhost__"));
SrsSetEnvConfig(hls_ctx_enabled, "SRS_VHOST_HLS_HLS_CTX", "off");
EXPECT_FALSE(conf.get_hls_ctx_enabled("__defaultVhost__"));
SrsSetEnvConfig(hls_ts_ctx_enabled, "SRS_VHOST_HLS_HLS_TS_CTX", "off");
EXPECT_FALSE(conf.get_hls_ts_ctx_enabled("__defaultVhost__"));
SrsSetEnvConfig(hls_fragment, "SRS_VHOST_HLS_HLS_FRAGMENT", "5");
EXPECT_EQ(5 * SRS_UTIME_SECONDS, conf.get_hls_fragment("__defaultVhost__"));
SrsSetEnvConfig(hls_td_ratio, "SRS_VHOST_HLS_HLS_TD_RATIO", "1.4");
EXPECT_EQ(1.4, conf.get_hls_td_ratio("__defaultVhost__"));
SrsSetEnvConfig(hls_aof_ratio, "SRS_VHOST_HLS_HLS_AOF_RATIO", "2.5");
EXPECT_EQ(2.5, conf.get_hls_aof_ratio("__defaultVhost__"));
SrsSetEnvConfig(hls_window, "SRS_VHOST_HLS_HLS_WINDOW", "30");
EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_hls_window("__defaultVhost__"));
SrsSetEnvConfig(hls_on_error, "SRS_VHOST_HLS_HLS_ON_ERROR", "xxx");
EXPECT_STREQ("xxx", conf.get_hls_on_error("__defaultVhost__").c_str());
SrsSetEnvConfig(hls_path, "SRS_VHOST_HLS_HLS_PATH", "xxx2");
EXPECT_STREQ("xxx2", conf.get_hls_path("__defaultVhost__").c_str());
SrsSetEnvConfig(hls_m3u8_file, "SRS_VHOST_HLS_HLS_M3U8_FILE", "xxx3");
EXPECT_STREQ("xxx3", conf.get_hls_m3u8_file("__defaultVhost__").c_str());
SrsSetEnvConfig(hls_ts_file, "SRS_VHOST_HLS_HLS_TS_FILE", "xxx4");
EXPECT_STREQ("xxx4", conf.get_hls_ts_file("__defaultVhost__").c_str());
SrsSetEnvConfig(hls_ts_floor, "SRS_VHOST_HLS_HLS_TS_FLOOR", "on");
EXPECT_TRUE(conf.get_hls_ts_floor("__defaultVhost__"));
SrsSetEnvConfig(hls_entry_prefix, "SRS_VHOST_HLS_HLS_ENTRY_PREFIX", "yyy");
EXPECT_STREQ("yyy", conf.get_hls_entry_prefix("__defaultVhost__").c_str());
SrsSetEnvConfig(hls_acodec, "SRS_VHOST_HLS_HLS_ACODEC", "yyy2");
EXPECT_STREQ("yyy2", conf.get_hls_acodec("__defaultVhost__").c_str());
SrsSetEnvConfig(hls_vcodec, "SRS_VHOST_HLS_HLS_VCODEC", "yyy3");
EXPECT_STREQ("yyy3", conf.get_hls_vcodec("__defaultVhost__").c_str());
SrsSetEnvConfig(hls_cleanup, "SRS_VHOST_HLS_HLS_CLEANUP", "off");
EXPECT_FALSE(conf.get_hls_cleanup("__defaultVhost__"));
SrsSetEnvConfig(hls_dispose, "SRS_VHOST_HLS_HLS_DISPOSE", "10");
EXPECT_EQ(10 * SRS_UTIME_SECONDS, conf.get_hls_dispose("__defaultVhost__"));
SrsSetEnvConfig(hls_nb_notify, "SRS_VHOST_HLS_HLS_NB_NOTIFY", "50");
EXPECT_EQ(50, conf.get_vhost_hls_nb_notify("__defaultVhost__"));
SrsSetEnvConfig(hls_wait_keyframe, "SRS_VHOST_HLS_HLS_WAIT_KEYFRAME", "off");
EXPECT_FALSE(conf.get_hls_wait_keyframe("__defaultVhost__"));
SrsSetEnvConfig(hls_keys, "SRS_VHOST_HLS_HLS_KEYS", "off");
EXPECT_FALSE(conf.get_hls_keys("__defaultVhost__"));
SrsSetEnvConfig(hls_fragments_per_key, "SRS_VHOST_HLS_HLS_FRAGMENTS_PER_KEY", "6");
EXPECT_EQ(6, conf.get_hls_fragments_per_key("__defaultVhost__"));
SrsSetEnvConfig(hls_key_file, "SRS_VHOST_HLS_HLS_KEY_FILE", "zzz");
EXPECT_STREQ("zzz", conf.get_hls_key_file("__defaultVhost__").c_str());
SrsSetEnvConfig(hls_key_file_path, "SRS_VHOST_HLS_HLS_KEY_FILE_PATH", "zzz2");
EXPECT_STREQ("zzz2", conf.get_hls_key_file_path("__defaultVhost__").c_str());
SrsSetEnvConfig(hls_key_url, "SRS_VHOST_HLS_HLS_KEY_URL", "zzz3");
EXPECT_STREQ("zzz3", conf.get_hls_key_url("__defaultVhost__").c_str());
SrsSetEnvConfig(hls_dts_directly, "SRS_VHOST_HLS_HLS_DTS_DIRECTLY", "off");
EXPECT_FALSE(conf.get_vhost_hls_dts_directly("__defaultVhost__"));
}
}

View file

@ -41,5 +41,27 @@ protected:
virtual srs_error_t build_buffer(std::string src, srs_internal::SrsConfigBuffer** pbuffer);
};
class ISrsSetEnvConfig
{
private:
std::string key;
public:
ISrsSetEnvConfig(const std::string& k, const std::string& v, bool overwrite) {
key = k;
srs_setenv(k, v, overwrite);
}
virtual ~ISrsSetEnvConfig() {
srs_unsetenv(key);
}
private:
// Adds, changes environment variables, which may starts with $.
int srs_setenv(const std::string& key, const std::string& value, bool overwrite);
// Deletes environment variables, which may starts with $.
int srs_unsetenv(const std::string& key);
};
#define SrsSetEnvConfig(instance, key, value) \
ISrsSetEnvConfig _SRS_free_##instance(key, value, true)
#endif