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, # the default chunk size is 128, max is 65536,
# some client does not support chunk size change, # some client does not support chunk size change,
# vhost chunk size will override the global value. # vhost chunk size will override the global value.
# Overwrite by env SRS_VHOST_CHUNK_SIZE for all vhosts.
# default: global chunk size. # default: global chunk size.
chunk_size 128; 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. # 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, # We can chnage the default ack size in server-side, to send acknowledge message,
# or the encoder maybe blocked after publishing for some time. # or the encoder maybe blocked after publishing for some time.
# Overwrite by env SRS_VHOST_IN_ACK_SIZE for all vhosts.
# Default: 0 # Default: 0
in_ack_size 0; in_ack_size 0;
# The output ack size, 0 to not set. # The output ack size, 0 to not set.
# This is used to notify the peer(player) to send acknowledge to server. # 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 # Default: 2500000
out_ack_size 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 # 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. # 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 # default: 2500
gop_cache_max_frames 2500; gop_cache_max_frames 2500;
@ -1700,6 +1704,7 @@ vhost hls.srs.com {
hls_ts_ctx on; hls_ts_ctx on;
# the hls fragment in seconds, the duration of a piece of ts. # 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 # default: 10
hls_fragment 10; hls_fragment 10;
# the hls m3u8 target duration ratio, # the hls m3u8 target duration ratio,
@ -1892,7 +1897,7 @@ vhost hds.srs.com {
# default: off # default: off
enabled on; enabled on;
# the hds fragment in seconds. # 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 # default: 10
hds_fragment 10; hds_fragment 10;
# the hds window in seconds, erase the segment when exceed the window. # 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 ## 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-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, SRT: Support transform tlpkdrop to tlpktdrop. 5.0.98
* v5.0, 2022-11-25, Config: Add ENV tips for config. 5.0.97 * 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() 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; static bool DEFAULT = false;
@ -2897,7 +2897,7 @@ string SrsConfig::get_server_id()
// Get the server id from env, config or DEFAULT. // Get the server id from env, config or DEFAULT.
string server_id; 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"); server_id = srs_getenv("srs.server_id");
} else { } else {
SrsConfDirective* conf = root->get("server_id"); SrsConfDirective* conf = root->get("server_id");
@ -2935,8 +2935,7 @@ vector<string> SrsConfig::get_listens()
std::vector<string> ports; std::vector<string> ports;
if (!srs_getenv("srs.listen").empty()) { // SRS_LISTEN if (!srs_getenv("srs.listen").empty()) { // SRS_LISTEN
ports.push_back(srs_getenv("srs.listen")); return srs_string_split(srs_getenv("srs.listen"), " ");
return ports;
} }
SrsConfDirective* conf = root->get("listen"); SrsConfDirective* conf = root->get("listen");
@ -3311,7 +3310,7 @@ int SrsConfig::get_dying_threshold()
int SrsConfig::get_dying_pulse() 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; 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; static srs_utime_t DEFAULT = 6 * SRS_UTIME_SECONDS;
srs_utime_t v = 0; 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); v = (srs_utime_t)(::atof(srs_getenv("srs.vhost.rtc.pli_for_rtmp").c_str()) * SRS_UTIME_SECONDS);
} else { } else {
SrsConfDirective* conf = get_rtc(vhost); SrsConfDirective* conf = get_rtc(vhost);
@ -4769,8 +4768,8 @@ bool SrsConfig::get_atc_auto(string vhost)
int SrsConfig::get_time_jitter(string vhost) int SrsConfig::get_time_jitter(string vhost)
{ {
if (!srs_getenv("srs.vhost.play.mw_latency").empty()) { // SRS_ if (!srs_getenv("srs.vhost.play.time_jitter").empty()) { // SRS_VHOST_PLAY_TIME_JITTER
return srs_time_jitter_string2int(srs_getenv("srs.vhost.play.mw_latency")); return srs_time_jitter_string2int(srs_getenv("srs.vhost.play.time_jitter"));
} }
static string DEFAULT = "full"; static string DEFAULT = "full";
@ -4916,6 +4915,8 @@ SrsConfDirective* SrsConfig::get_refer_publish(string vhost)
int SrsConfig::get_in_ack_size(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; static int DEFAULT = 0;
SrsConfDirective* conf = get_vhost(vhost); 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) 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; static int DEFAULT = 2500000;
SrsConfDirective* conf = get_vhost(vhost); SrsConfDirective* conf = get_vhost(vhost);
@ -4950,6 +4953,8 @@ int SrsConfig::get_out_ack_size(string vhost)
int SrsConfig::get_chunk_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()) { if (vhost.empty()) {
return get_global_chunk_size(); 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) 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()); int v = ::atoi(srs_getenv("srs.vhost.play.mw_latency").c_str());
if (is_rtc && v > 0) { if (is_rtc && v > 0) {
srs_warn("For RTC, we ignore mw_latency"); 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) 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()); int v = ::atoi(srs_getenv("srs.vhost.play.mw_msgs").c_str());
if (v > SRS_PERF_MW_MSGS) { if (v > SRS_PERF_MW_MSGS) {
srs_warn("reset mw_msgs %d to max %d", 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() 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"); SrsConfDirective* conf = root->get("chunk_size");
if (!conf || conf->arg0().empty()) { if (!conf || conf->arg0().empty()) {
@ -6639,6 +6644,8 @@ bool SrsConfig::get_hls_enabled(string vhost)
bool SrsConfig::get_hls_enabled(SrsConfDirective* 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; static bool DEFAULT = false;
SrsConfDirective* conf = vhost->get("hls"); 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) 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; static bool DEFAULT = false;
SrsConfDirective* conf = get_hls(vhost); SrsConfDirective* conf = get_hls(vhost);
@ -7239,6 +7248,8 @@ bool SrsConfig::get_dvr_enabled(string vhost)
bool SrsConfig::get_dvr_enabled(SrsConfDirective* 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; static bool DEFAULT = false;
SrsConfDirective* conf = vhost->get("dvr"); 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) int SrsConfig::get_dvr_time_jitter(string vhost)
{ {
if (!srs_getenv("srs.vhost.dvr.dvr_wait_keyframe").empty()) { // SRS_ if (!srs_getenv("srs.vhost.dvr.time_jitter").empty()) { // SRS_VHOST_DVR_TIME_JITTER
return srs_time_jitter_string2int(srs_getenv("srs.vhost.dvr.dvr_wait_keyframe")); return srs_time_jitter_string2int(srs_getenv("srs.vhost.dvr.time_jitter"));
} }
static string DEFAULT = "full"; static string DEFAULT = "full";
@ -8103,7 +8114,7 @@ string SrsConfig::get_https_stream_ssl_cert()
bool SrsConfig::get_vhost_http_enabled(string vhost) 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; static bool DEFAULT = false;
@ -8127,7 +8138,7 @@ bool SrsConfig::get_vhost_http_enabled(string vhost)
string SrsConfig::get_vhost_http_mount(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]/"; static string DEFAULT = "[vhost]/";
@ -8151,7 +8162,7 @@ string SrsConfig::get_vhost_http_mount(string vhost)
string SrsConfig::get_vhost_http_dir(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"; 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) 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; static bool DEFAULT = false;
SrsConfDirective* conf = get_vhost(vhost); 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) 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; 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_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; 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) 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"; static string DEFAULT = "[vhost]/[app]/[stream].flv";

View file

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

File diff suppressed because it is too large Load diff

View file

@ -41,5 +41,27 @@ protected:
virtual srs_error_t build_buffer(std::string src, srs_internal::SrsConfigBuffer** pbuffer); 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 #endif