From 336795604c734874372f040cd247337e9602bd9e Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 6 Apr 2021 07:59:37 +0800 Subject: [PATCH] Threads-Hybrid: Support mulitple hybrid/stream servers 1. For hybrid RTMP/HTTP/RTC servers. 2. Config hybrids in threads. 3. Get hybrid server config with index. --- trunk/conf/full.conf | 4 + trunk/src/app/srs_app_config.cpp | 234 +++++++++++++++++++++---------- trunk/src/app/srs_app_config.hpp | 75 +++++----- 3 files changed, 207 insertions(+), 106 deletions(-) diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index 59a9fd3951..4119f8c2e6 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -129,6 +129,10 @@ threads { # without proxy by hybrid(except the few head packets). # Default: off async_tunnel off; + # The number of hybrid threads to use, MUST >=1. + # Note that there MUST be same number of stream sections. + # Default: 1 + hybrids 1; # CPU set for affinity, for example: # 0 means CPU0 # 0-3 means CPU0, CPU1, CPU2 diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 5f22a23fbf..551c940760 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -738,10 +738,10 @@ string SrsConfDirective::arg3() return ""; } -SrsConfDirective* SrsConfDirective::at(int index) +SrsConfDirective* SrsConfDirective::at(int stream_index) { - srs_assert(index < (int)directives.size()); - return directives.at(index); + srs_assert(stream_index < (int)directives.size()); + return directives.at(stream_index); } SrsConfDirective* SrsConfDirective::get(string _name) @@ -3284,6 +3284,10 @@ srs_error_t SrsConfig::check_config() if ((err = check_number_connections()) != srs_success) { return srs_error_wrap(err, "check connections"); } + + if ((err = check_hybrids()) != srs_success) { + return srs_error_wrap(err, "check hybrids"); + } return err; } @@ -3787,6 +3791,62 @@ srs_error_t SrsConfig::check_number_connections() } // LCOV_EXCL_STOP +srs_error_t SrsConfig::check_hybrids() +{ + srs_error_t err = srs_success; + + // There MUST be at least one stream/hybrid. + int hybrids = get_threads_hybrids(); + if (hybrids < 1) { + return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "hybrids MUST >=1, actual %d", hybrids); + } + + // The number of hybrids MUST be equal to the streams. + vector streams; + for (int i = 0; i < (int)root->directives.size(); i++) { + SrsConfDirective* conf = root->at(i); + if (conf->name == "stream") { + streams.push_back(conf); + } + } + + if (hybrids != (int)streams.size()) { + return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "hybrids=%d, streams=%d, not equal", hybrids, (int)streams.size()); + } + + // For each stream, the UDP listen MUST not be the same. + vector udp_ports; + for (int i = 0; i < (int)streams.size(); i++) { + int port = get_rtc_server_listen(i); + if (std::find(udp_ports.begin(), udp_ports.end(), port) != udp_ports.end()) { + return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "RTC port=%d duplicated", port); + } + udp_ports.push_back(port); + } + + // TODO: FIXME: For edge, the RTMP/HTTP port is OK to be the same, but it's too complex. + // For each stream, the TCP listen MUST not be the same. + vector tcp_ports; + for (int i = 0; i < (int)streams.size(); i++) { + string port = get_http_stream_listen(i); + if (std::find(tcp_ports.begin(), tcp_ports.end(), port) != tcp_ports.end()) { + return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "HTTP port=%s duplicated", port.c_str()); + } + tcp_ports.push_back(port); + + vector ports = get_listens(i); + for (int j = 0; j < (int)ports.size(); j++) { + port = ports.at(j); + if (std::find(tcp_ports.begin(), tcp_ports.end(), port) != tcp_ports.end()) { + return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "RTMP port=%s duplicated", port.c_str()); + } + tcp_ports.push_back(port); + } + } + + return err; +} + srs_error_t SrsConfig::parse_buffer(SrsConfigBuffer* buffer) { srs_error_t err = srs_success; @@ -3828,16 +3888,31 @@ SrsConfDirective* SrsConfig::get_root() return root; } -SrsConfDirective* SrsConfig::get_first_stream() +SrsConfDirective* SrsConfig::get_stream_at(int stream_index) { - return root->get("stream"); + int matched = 0; + for (int i = 0; i < (int)root->directives.size(); i++) { + SrsConfDirective* conf = root->at(i); + + if (conf->name != "stream") { + continue; + } + + if (matched++ != stream_index) { + continue; + } + + return conf; + } + + return NULL; } -int SrsConfig::get_max_connections() +int SrsConfig::get_max_connections(int stream_index) { static int DEFAULT = 1000; - SrsConfDirective* conf = get_first_stream(); + SrsConfDirective* conf = get_stream_at(stream_index); if (!conf) { return DEFAULT; } @@ -3850,11 +3925,11 @@ int SrsConfig::get_max_connections() return ::atoi(conf->arg0().c_str()); } -vector SrsConfig::get_listens() +vector SrsConfig::get_listens(int stream_index) { std::vector ports; - SrsConfDirective* conf = get_first_stream(); + SrsConfDirective* conf = get_stream_at(stream_index); if (!conf) { return ports; } @@ -4133,6 +4208,23 @@ bool SrsConfig::get_threads_async_tunnel() return SRS_CONF_PERFER_FALSE(conf->arg0()); } +int SrsConfig::get_threads_hybrids() +{ + static int DEFAULT = 1; + + SrsConfDirective* conf = root->get("threads"); + if (!conf) { + return DEFAULT; + } + + conf = conf->get("hybrids"); + if (!conf) { + return DEFAULT; + } + + return ::atoi(conf->arg0().c_str()); +} + bool SrsConfig::get_threads_cpu_affinity(std::string label, int* start, int* end) { static int DEFAULT_START = 0; @@ -4720,9 +4812,9 @@ srs_utime_t SrsConfig::get_stream_caster_gb28181_sip_query_catalog_interval(SrsC return (srs_utime_t)(::atoi(conf->arg0().c_str()) * SRS_UTIME_SECONDS); } -SrsConfDirective* SrsConfig::get_first_rtc_server() +SrsConfDirective* SrsConfig::get_rtc_server_at(int stream_index) { - SrsConfDirective* conf = get_first_stream(); + SrsConfDirective* conf = get_stream_at(stream_index); if (!conf) { return NULL; } @@ -4730,9 +4822,9 @@ SrsConfDirective* SrsConfig::get_first_rtc_server() return conf->get("rtc_server"); } -bool SrsConfig::get_rtc_server_enabled() +bool SrsConfig::get_rtc_server_enabled(int stream_index) { - SrsConfDirective* conf = get_first_rtc_server(); + SrsConfDirective* conf = get_rtc_server_at(stream_index); return get_rtc_server_enabled(conf); } @@ -4752,11 +4844,11 @@ bool SrsConfig::get_rtc_server_enabled(SrsConfDirective* conf) return SRS_CONF_PERFER_FALSE(conf->arg0()); } -int SrsConfig::get_rtc_server_listen() +int SrsConfig::get_rtc_server_listen(int stream_index) { static int DEFAULT = 8000; - SrsConfDirective* conf = get_first_rtc_server(); + SrsConfDirective* conf = get_rtc_server_at(stream_index); if (!conf) { return DEFAULT; } @@ -4769,11 +4861,11 @@ int SrsConfig::get_rtc_server_listen() return ::atoi(conf->arg0().c_str()); } -std::string SrsConfig::get_rtc_server_candidates() +std::string SrsConfig::get_rtc_server_candidates(int stream_index) { static string DEFAULT = "*"; - SrsConfDirective* conf = get_first_rtc_server(); + SrsConfDirective* conf = get_rtc_server_at(stream_index); if (!conf) { return DEFAULT; } @@ -4796,11 +4888,11 @@ std::string SrsConfig::get_rtc_server_candidates() return conf->arg0(); } -std::string SrsConfig::get_rtc_server_ip_family() +std::string SrsConfig::get_rtc_server_ip_family(int stream_index) { static string DEFAULT = "ipv4"; - SrsConfDirective* conf = get_first_rtc_server(); + SrsConfDirective* conf = get_rtc_server_at(stream_index); if (!conf) { return DEFAULT; } @@ -4813,11 +4905,11 @@ std::string SrsConfig::get_rtc_server_ip_family() return conf->arg0(); } -bool SrsConfig::get_rtc_server_ecdsa() +bool SrsConfig::get_rtc_server_ecdsa(int stream_index) { static bool DEFAULT = true; - SrsConfDirective* conf = get_first_rtc_server(); + SrsConfDirective* conf = get_rtc_server_at(stream_index); if (!conf) { return DEFAULT; } @@ -4830,11 +4922,11 @@ bool SrsConfig::get_rtc_server_ecdsa() return SRS_CONF_PERFER_TRUE(conf->arg0()); } -bool SrsConfig::get_rtc_server_encrypt() +bool SrsConfig::get_rtc_server_encrypt(int stream_index) { static bool DEFAULT = true; - SrsConfDirective* conf = get_first_rtc_server(); + SrsConfDirective* conf = get_rtc_server_at(stream_index); if (!conf) { return DEFAULT; } @@ -4847,9 +4939,9 @@ bool SrsConfig::get_rtc_server_encrypt() return SRS_CONF_PERFER_TRUE(conf->arg0()); } -int SrsConfig::get_rtc_server_reuseport() +int SrsConfig::get_rtc_server_reuseport(int stream_index) { - int v = get_rtc_server_reuseport2(); + int v = get_rtc_server_reuseport2(stream_index); #if !defined(SO_REUSEPORT) if (v > 1) { @@ -4861,11 +4953,11 @@ int SrsConfig::get_rtc_server_reuseport() return v; } -int SrsConfig::get_rtc_server_reuseport2() +int SrsConfig::get_rtc_server_reuseport2(int stream_index) { static int DEFAULT = 1; - SrsConfDirective* conf = get_first_rtc_server(); + SrsConfDirective* conf = get_rtc_server_at(stream_index); if (!conf) { return DEFAULT; } @@ -4878,11 +4970,11 @@ int SrsConfig::get_rtc_server_reuseport2() return ::atoi(conf->arg0().c_str()); } -bool SrsConfig::get_rtc_server_merge_nalus() +bool SrsConfig::get_rtc_server_merge_nalus(int stream_index) { static int DEFAULT = false; - SrsConfDirective* conf = get_first_rtc_server(); + SrsConfDirective* conf = get_rtc_server_at(stream_index); if (!conf) { return DEFAULT; } @@ -4895,11 +4987,11 @@ bool SrsConfig::get_rtc_server_merge_nalus() return SRS_CONF_PERFER_TRUE(conf->arg0()); } -bool SrsConfig::get_rtc_server_perf_stat() +bool SrsConfig::get_rtc_server_perf_stat(int stream_index) { static bool DEFAULT = false; - SrsConfDirective* conf = get_first_rtc_server(); + SrsConfDirective* conf = get_rtc_server_at(stream_index); if (!conf) { return DEFAULT; } @@ -4912,9 +5004,9 @@ bool SrsConfig::get_rtc_server_perf_stat() return SRS_CONF_PERFER_FALSE(conf->arg0()); } -SrsConfDirective* SrsConfig::get_rtc_server_rtp_cache() +SrsConfDirective* SrsConfig::get_rtc_server_rtp_cache(int stream_index) { - SrsConfDirective* conf = get_first_rtc_server(); + SrsConfDirective* conf = get_rtc_server_at(stream_index); if (!conf) { return NULL; } @@ -4927,11 +5019,11 @@ SrsConfDirective* SrsConfig::get_rtc_server_rtp_cache() return conf; } -bool SrsConfig::get_rtc_server_rtp_cache_enabled() +bool SrsConfig::get_rtc_server_rtp_cache_enabled(int stream_index) { static bool DEFAULT = true; - SrsConfDirective* conf = get_rtc_server_rtp_cache(); + SrsConfDirective* conf = get_rtc_server_rtp_cache(stream_index); if (!conf) { return DEFAULT; } @@ -4944,11 +5036,11 @@ bool SrsConfig::get_rtc_server_rtp_cache_enabled() return SRS_CONF_PERFER_TRUE(conf->arg0()); } -uint64_t SrsConfig::get_rtc_server_rtp_cache_pkt_size() +uint64_t SrsConfig::get_rtc_server_rtp_cache_pkt_size(int stream_index) { int DEFAULT = 64 * 1024 * 1024; - SrsConfDirective* conf = get_rtc_server_rtp_cache(); + SrsConfDirective* conf = get_rtc_server_rtp_cache(stream_index); if (!conf) { return DEFAULT; } @@ -4961,11 +5053,11 @@ uint64_t SrsConfig::get_rtc_server_rtp_cache_pkt_size() return 1024 * (uint64_t)(1024 * ::atof(conf->arg0().c_str())); } -uint64_t SrsConfig::get_rtc_server_rtp_cache_payload_size() +uint64_t SrsConfig::get_rtc_server_rtp_cache_payload_size(int stream_index) { int DEFAULT = 16 * 1024 * 1024; - SrsConfDirective* conf = get_rtc_server_rtp_cache(); + SrsConfDirective* conf = get_rtc_server_rtp_cache(stream_index); if (!conf) { return DEFAULT; } @@ -4978,9 +5070,9 @@ uint64_t SrsConfig::get_rtc_server_rtp_cache_payload_size() return 1024 * (uint64_t)(1024 * ::atof(conf->arg0().c_str())); } -SrsConfDirective* SrsConfig::get_rtc_server_rtp_msg_cache() +SrsConfDirective* SrsConfig::get_rtc_server_rtp_msg_cache(int stream_index) { - SrsConfDirective* conf = get_first_rtc_server(); + SrsConfDirective* conf = get_rtc_server_at(stream_index); if (!conf) { return NULL; } @@ -4993,11 +5085,11 @@ SrsConfDirective* SrsConfig::get_rtc_server_rtp_msg_cache() return conf; } -bool SrsConfig::get_rtc_server_rtp_msg_cache_enabled() +bool SrsConfig::get_rtc_server_rtp_msg_cache_enabled(int stream_index) { static bool DEFAULT = true; - SrsConfDirective* conf = get_rtc_server_rtp_msg_cache(); + SrsConfDirective* conf = get_rtc_server_rtp_msg_cache(stream_index); if (!conf) { return DEFAULT; } @@ -5010,11 +5102,11 @@ bool SrsConfig::get_rtc_server_rtp_msg_cache_enabled() return SRS_CONF_PERFER_TRUE(conf->arg0()); } -uint64_t SrsConfig::get_rtc_server_rtp_msg_cache_msg_size() +uint64_t SrsConfig::get_rtc_server_rtp_msg_cache_msg_size(int stream_index) { int DEFAULT = 16 * 1024 * 1024; - SrsConfDirective* conf = get_rtc_server_rtp_msg_cache(); + SrsConfDirective* conf = get_rtc_server_rtp_msg_cache(stream_index); if (!conf) { return DEFAULT; } @@ -5027,11 +5119,11 @@ uint64_t SrsConfig::get_rtc_server_rtp_msg_cache_msg_size() return 1024 * (uint64_t)(1024 * ::atof(conf->arg0().c_str())); } -uint64_t SrsConfig::get_rtc_server_rtp_msg_cache_buffer_size() +uint64_t SrsConfig::get_rtc_server_rtp_msg_cache_buffer_size(int stream_index) { int DEFAULT = 512 * 1024 * 1024; - SrsConfDirective* conf = get_rtc_server_rtp_msg_cache(); + SrsConfDirective* conf = get_rtc_server_rtp_msg_cache(stream_index); if (!conf) { return DEFAULT; } @@ -5044,11 +5136,11 @@ uint64_t SrsConfig::get_rtc_server_rtp_msg_cache_buffer_size() return 1024 * (uint64_t)(1024 * ::atof(conf->arg0().c_str())); } -bool SrsConfig::get_rtc_server_black_hole() +bool SrsConfig::get_rtc_server_black_hole(int stream_index) { static bool DEFAULT = false; - SrsConfDirective* conf = get_first_rtc_server(); + SrsConfDirective* conf = get_rtc_server_at(stream_index); if (!conf) { return DEFAULT; } @@ -5066,11 +5158,11 @@ bool SrsConfig::get_rtc_server_black_hole() return SRS_CONF_PERFER_FALSE(conf->arg0()); } -std::string SrsConfig::get_rtc_server_black_hole_addr() +std::string SrsConfig::get_rtc_server_black_hole_addr(int stream_index) { static string DEFAULT = ""; - SrsConfDirective* conf = get_first_rtc_server(); + SrsConfDirective* conf = get_rtc_server_at(stream_index); if (!conf) { return DEFAULT; } @@ -8200,9 +8292,9 @@ string SrsConfig::get_default_app_name() { return conf->arg0(); } -SrsConfDirective* SrsConfig::get_first_http_stream() +SrsConfDirective* SrsConfig::get_http_stream_at(int stream_index) { - SrsConfDirective* conf = get_first_stream(); + SrsConfDirective* conf = get_stream_at(stream_index); if (!conf) { return NULL; } @@ -8210,9 +8302,9 @@ SrsConfDirective* SrsConfig::get_first_http_stream() return conf->get("http_server"); } -bool SrsConfig::get_http_stream_enabled() +bool SrsConfig::get_http_stream_enabled(int stream_index) { - SrsConfDirective* conf = get_first_http_stream(); + SrsConfDirective* conf = get_http_stream_at(stream_index); return get_http_stream_enabled(conf); } @@ -8232,11 +8324,11 @@ bool SrsConfig::get_http_stream_enabled(SrsConfDirective* conf) return SRS_CONF_PERFER_FALSE(conf->arg0()); } -string SrsConfig::get_http_stream_listen() +string SrsConfig::get_http_stream_listen(int stream_index) { static string DEFAULT = "8080"; - SrsConfDirective* conf = get_first_http_stream(); + SrsConfDirective* conf = get_http_stream_at(stream_index); if (!conf) { return DEFAULT; } @@ -8249,11 +8341,11 @@ string SrsConfig::get_http_stream_listen() return conf->arg0(); } -string SrsConfig::get_http_stream_dir() +string SrsConfig::get_http_stream_dir(int stream_index) { static string DEFAULT = "./objs/nginx/html"; - SrsConfDirective* conf = get_first_http_stream(); + SrsConfDirective* conf = get_http_stream_at(stream_index); if (!conf) { return DEFAULT; } @@ -8266,11 +8358,11 @@ string SrsConfig::get_http_stream_dir() return conf->arg0(); } -bool SrsConfig::get_http_stream_crossdomain() +bool SrsConfig::get_http_stream_crossdomain(int stream_index) { static bool DEFAULT = true; - SrsConfDirective* conf = get_first_http_stream(); + SrsConfDirective* conf = get_http_stream_at(stream_index); if (!conf) { return DEFAULT; } @@ -8283,9 +8375,9 @@ bool SrsConfig::get_http_stream_crossdomain() return SRS_CONF_PERFER_TRUE(conf->arg0()); } -SrsConfDirective* SrsConfig::get_https_stream() +SrsConfDirective* SrsConfig::get_https_stream(int stream_index) { - SrsConfDirective* conf = get_first_http_stream(); + SrsConfDirective* conf = get_http_stream_at(stream_index); if (!conf) { return NULL; } @@ -8293,11 +8385,11 @@ SrsConfDirective* SrsConfig::get_https_stream() return conf->get("https"); } -bool SrsConfig::get_https_stream_enabled() +bool SrsConfig::get_https_stream_enabled(int stream_index) { static bool DEFAULT = false; - SrsConfDirective* conf = get_https_stream(); + SrsConfDirective* conf = get_https_stream(stream_index); if (!conf) { return DEFAULT; } @@ -8310,11 +8402,11 @@ bool SrsConfig::get_https_stream_enabled() return SRS_CONF_PERFER_FALSE(conf->arg0()); } -string SrsConfig::get_https_stream_listen() +string SrsConfig::get_https_stream_listen(int stream_index) { static string DEFAULT = "8088"; - SrsConfDirective* conf = get_https_stream(); + SrsConfDirective* conf = get_https_stream(stream_index); if (!conf) { return DEFAULT; } @@ -8327,11 +8419,11 @@ string SrsConfig::get_https_stream_listen() return conf->arg0(); } -string SrsConfig::get_https_stream_ssl_key() +string SrsConfig::get_https_stream_ssl_key(int stream_index) { static string DEFAULT = "./conf/server.key"; - SrsConfDirective* conf = get_https_stream(); + SrsConfDirective* conf = get_https_stream(stream_index); if (!conf) { return DEFAULT; } @@ -8344,11 +8436,11 @@ string SrsConfig::get_https_stream_ssl_key() return conf->arg0(); } -string SrsConfig::get_https_stream_ssl_cert() +string SrsConfig::get_https_stream_ssl_cert(int stream_index) { static string DEFAULT = "./conf/server.crt"; - SrsConfDirective* conf = get_https_stream(); + SrsConfDirective* conf = get_https_stream(stream_index); if (!conf) { return DEFAULT; } diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index efce826456..33bb1fcafb 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -401,6 +401,7 @@ class SrsConfig protected: virtual srs_error_t check_normal_config(); virtual srs_error_t check_number_connections(); + virtual srs_error_t check_hybrids(); protected: // Parse config from the buffer. // @param buffer, the config buffer, user must delete it. @@ -418,8 +419,8 @@ class SrsConfig // The root directive, no name and args, contains directives. // All directive parsed can retrieve from root. virtual SrsConfDirective* get_root(); - // Get the first stream config. - virtual SrsConfDirective* get_first_stream(); + // Get the stream config at index. + virtual SrsConfDirective* get_stream_at(int index); // Get the daemon config. // If true, SRS will run in daemon mode, fork and fork to reap the // grand-child process to init process. @@ -430,11 +431,11 @@ class SrsConfig // for example, when you need SRS to service 10000+ connections, // user must use "ulimit -HSn 10000" and config the max connections // of SRS. - virtual int get_max_connections(); + virtual int get_max_connections(int stream_index = 0); // Get the listen port of SRS. // user can specifies multiple listen ports, // each args of directive is a listen port. - virtual std::vector get_listens(); + virtual std::vector get_listens(int stream_index = 0); // Get the pid file path. // The pid file is used to save the pid of SRS, // use file lock to prevent multiple SRS starting. @@ -476,6 +477,7 @@ class SrsConfig virtual int get_threads_async_recv(); virtual int get_threads_async_send(); virtual bool get_threads_async_tunnel(); + virtual int get_threads_hybrids(); virtual bool get_threads_cpu_affinity(std::string label, int* start, int* end); virtual int get_threads_max_recv_queue(); virtual int get_high_threshold(); @@ -521,35 +523,36 @@ class SrsConfig // rtc section private: - SrsConfDirective* get_first_rtc_server(); + // Get the RTC server config at index. + SrsConfDirective* get_rtc_server_at(int index); public: - virtual bool get_rtc_server_enabled(); + virtual bool get_rtc_server_enabled(int stream_index = 0); virtual bool get_rtc_server_enabled(SrsConfDirective* conf); - virtual int get_rtc_server_listen(); - virtual std::string get_rtc_server_candidates(); - virtual std::string get_rtc_server_ip_family(); - virtual bool get_rtc_server_ecdsa(); - virtual bool get_rtc_server_encrypt(); - virtual int get_rtc_server_reuseport(); - virtual bool get_rtc_server_merge_nalus(); - virtual bool get_rtc_server_perf_stat(); + virtual int get_rtc_server_listen(int stream_index = 0); + virtual std::string get_rtc_server_candidates(int stream_index = 0); + virtual std::string get_rtc_server_ip_family(int stream_index = 0); + virtual bool get_rtc_server_ecdsa(int stream_index = 0); + virtual bool get_rtc_server_encrypt(int stream_index = 0); + virtual int get_rtc_server_reuseport(int stream_index = 0); + virtual bool get_rtc_server_merge_nalus(int stream_index = 0); + virtual bool get_rtc_server_perf_stat(int stream_index = 0); private: - SrsConfDirective* get_rtc_server_rtp_cache(); + SrsConfDirective* get_rtc_server_rtp_cache(int stream_index = 0); public: - virtual bool get_rtc_server_rtp_cache_enabled(); - virtual uint64_t get_rtc_server_rtp_cache_pkt_size(); - virtual uint64_t get_rtc_server_rtp_cache_payload_size(); + virtual bool get_rtc_server_rtp_cache_enabled(int stream_index = 0); + virtual uint64_t get_rtc_server_rtp_cache_pkt_size(int stream_index = 0); + virtual uint64_t get_rtc_server_rtp_cache_payload_size(int stream_index = 0); private: - virtual SrsConfDirective* get_rtc_server_rtp_msg_cache(); + virtual SrsConfDirective* get_rtc_server_rtp_msg_cache(int stream_index = 0); public: - virtual bool get_rtc_server_rtp_msg_cache_enabled(); - virtual uint64_t get_rtc_server_rtp_msg_cache_msg_size(); - virtual uint64_t get_rtc_server_rtp_msg_cache_buffer_size(); + virtual bool get_rtc_server_rtp_msg_cache_enabled(int stream_index = 0); + virtual uint64_t get_rtc_server_rtp_msg_cache_msg_size(int stream_index = 0); + virtual uint64_t get_rtc_server_rtp_msg_cache_buffer_size(int stream_index = 0); public: - virtual bool get_rtc_server_black_hole(); - virtual std::string get_rtc_server_black_hole_addr(); + virtual bool get_rtc_server_black_hole(int stream_index = 0); + virtual std::string get_rtc_server_black_hole_addr(int stream_index = 0); private: - virtual int get_rtc_server_reuseport2(); + virtual int get_rtc_server_reuseport2(int stream_index = 0); public: SrsConfDirective* get_rtc(std::string vhost); @@ -1045,27 +1048,29 @@ class SrsConfig virtual std::string get_https_api_ssl_cert(); // http stream section private: - SrsConfDirective* get_first_http_stream(); + // Get the HTTP stream config at index. + SrsConfDirective* get_http_stream_at(int index); // Whether http stream enabled. virtual bool get_http_stream_enabled(SrsConfDirective* conf); public: // Whether http stream enabled. // TODO: FIXME: rename to http_static. - virtual bool get_http_stream_enabled(); + virtual bool get_http_stream_enabled(int stream_index = 0); // Get the http stream listen port. - virtual std::string get_http_stream_listen(); + virtual std::string get_http_stream_listen(int stream_index = 0); // Get the http stream root dir. - virtual std::string get_http_stream_dir(); + virtual std::string get_http_stream_dir(int stream_index = 0); // Whether enable crossdomain for http static and stream server. - virtual bool get_http_stream_crossdomain(); + virtual bool get_http_stream_crossdomain(int stream_index = 0); // https api section private: - SrsConfDirective* get_https_stream(); + // Get the HTTPS stream config at index. + SrsConfDirective* get_https_stream(int index); public: - virtual bool get_https_stream_enabled(); - virtual std::string get_https_stream_listen(); - virtual std::string get_https_stream_ssl_key(); - virtual std::string get_https_stream_ssl_cert(); + virtual bool get_https_stream_enabled(int stream_index = 0); + virtual std::string get_https_stream_listen(int stream_index = 0); + virtual std::string get_https_stream_ssl_key(int stream_index = 0); + virtual std::string get_https_stream_ssl_cert(int stream_index = 0); public: // Get whether vhost enabled http stream virtual bool get_vhost_http_enabled(std::string vhost);